Skip to content

Date Periods & Time Intelligence

OnlyMetrix has a built-in semantic date system. Instead of writing date math in SQL, use keywords like last_month or ytd and the engine resolves them to exact date ranges.

Period keywords

Single day

KeywordResolves to
todayStart of today → start of tomorrow
yesterdayStart of yesterday → start of today

To-date periods

KeywordResolves to
wtd / week_to_dateStart of current week → today
mtd / month_to_date1st of current month → today
qtd / quarter_to_date1st of current quarter → today
ytd / year_to_date1st of fiscal year → today

Complete previous periods

KeywordResolves to
last_weekFull previous Monday–Sunday
last_monthFull previous calendar month
last_quarterFull previous quarter
last_yearFull previous fiscal year

Current periods

KeywordResolves to
this_weekCurrent week (Monday → Sunday)
this_monthCurrent calendar month
this_quarterCurrent fiscal quarter
this_yearCurrent fiscal year

Lookback periods

PatternExampleResolves to
last_Nd / last_N_dayslast_7d, last_30dPast N days from today
last_Nwlast_4wPast N weeks
last_Nmlast_6mPast N months

Explicit range

range:2026-01-01,2026-03-31

Using in queries

API

Pass the period parameter to any metric query:

bash
curl -X POST https://api.onlymetrix.com/v1/metrics/total_revenue \
  -H "Authorization: Bearer $API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"period": "last_quarter"}'

CLI

bash
omx metrics query total_revenue --period last_month

AI Agent

Just ask naturally — the agent maps your language to the right period:

  • "How was revenue last month?" → last_month
  • "Show me this quarter so far" → qtd
  • "Compare last 30 days" → last_30d

Fiscal calendar support

If your fiscal year doesn't start in January, configure it per-tenant:

yaml
time:
  fiscal_year_start: april    # FY starts April 1
  week_start: monday          # or sunday

When configured:

  • ytd resolves from your fiscal year start, not January 1
  • qtd uses fiscal quarters (e.g., Q1 = Apr–Jun)
  • last_year returns the previous fiscal year
  • last_quarter returns the previous fiscal quarter

Comparison periods

The engine also supports automatic comparison. When you query with granularity and period, the system can generate comparison datasets (e.g., current month vs. previous month) for the AI agent to analyze.

Date-aware agent

The AI agent auto-discovers the actual time range of your data by querying MIN/MAX on date columns. This means when you ask "how was last month?", the agent interprets it relative to your data's end date — not today's date. This is critical for historical datasets.

MIT Licensed (SDK) | Proprietary (Server)