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
| Keyword | Resolves to |
|---|---|
today | Start of today → start of tomorrow |
yesterday | Start of yesterday → start of today |
To-date periods
| Keyword | Resolves to |
|---|---|
wtd / week_to_date | Start of current week → today |
mtd / month_to_date | 1st of current month → today |
qtd / quarter_to_date | 1st of current quarter → today |
ytd / year_to_date | 1st of fiscal year → today |
Complete previous periods
| Keyword | Resolves to |
|---|---|
last_week | Full previous Monday–Sunday |
last_month | Full previous calendar month |
last_quarter | Full previous quarter |
last_year | Full previous fiscal year |
Current periods
| Keyword | Resolves to |
|---|---|
this_week | Current week (Monday → Sunday) |
this_month | Current calendar month |
this_quarter | Current fiscal quarter |
this_year | Current fiscal year |
Lookback periods
| Pattern | Example | Resolves to |
|---|---|---|
last_Nd / last_N_days | last_7d, last_30d | Past N days from today |
last_Nw | last_4w | Past N weeks |
last_Nm | last_6m | Past N months |
Explicit range
range:2026-01-01,2026-03-31Using in queries
API
Pass the period parameter to any metric query:
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
omx metrics query total_revenue --period last_monthAI 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:
time:
fiscal_year_start: april # FY starts April 1
week_start: monday # or sundayWhen configured:
ytdresolves from your fiscal year start, not January 1qtduses fiscal quarters (e.g., Q1 = Apr–Jun)last_yearreturns the previous fiscal yearlast_quarterreturns 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.