Azure Cost Management actual/amortized cost over a trailing RESTATEMENT window, as typed DuckDB rows (date, grouping dims, Float64 cost, currency). Costs are restated retroactively, so each scan re-pulls [from−lookback, to] and the caller MUST apply by OVERWRITE keyed on (scope, date, grouping dims) — never a blind INSERT (that double-counts, SPEC §2 #2). The new high-water to rides back on a marker row as _watermark_next (persist only after the rows are durable); _restated_from is the low edge to overwrite; _key_columns guards the group_by key shape — a change is a full reload, not an incremental resume (§2 #3). Continuation pages re-POST the ORIGINAL query body (the $skiptoken is in the nextLink URL). AUDIENCE: arm.
Positional arguments
Named arguments
restatement_lookback_days :=
BIGINT
Returns columns
Returns columns · depends on the arguments
Default (empty `group_by`) — no dimension columns
Grouped (e.g. `group_by := 'Dimension:ResourceGroup'`) — one extra dimension column
Examples (5)
Daily actual cost by resource group for June (data rows only; the date filter drops the 7-day restatement lookback the scan also re-pulls)
SELECT date, "ResourceGroup", cost, currency
FROM azure.main.cost_query('subscriptions/<guid>', '2026-06-01', '2026-06-30', granularity := 'Daily', group_by := 'Dimension:ResourceGroup')
WHERE _row_kind IS NULL AND date >= '2026-06-01'
ORDER BY date, "ResourceGroup";
Monthly amortized cost totals for January–June (the date filter drops the open prior month the amortized lookback also re-pulls)
SELECT date, cost, currency
FROM azure.main.cost_query('subscriptions/<guid>', '2026-01-01', '2026-06-30', granularity := 'Monthly', cost_type := 'AmortizedCost')
WHERE _row_kind IS NULL AND date >= '2026-01-01'
ORDER BY date;
Read the restatement watermark to persist for the next incremental scan
SELECT _watermark_next, _restated_from, _key_columns
FROM azure.main.cost_query('subscriptions/<guid>', '2026-06-01', '2026-06-30')
WHERE _row_kind = 'marker';
2 more examples
Daily cost by service and cost-center tag for June (multi-axis grouping; restatement-lookback days filtered out)
SELECT date, "ServiceName", "costcenter", cost, currency
FROM azure.main.cost_query('subscriptions/<guid>', '2026-06-01', '2026-06-30', granularity := 'Daily', group_by := 'Dimension:ServiceName,TagKey:costcenter')
WHERE _row_kind IS NULL AND date >= '2026-06-01'
ORDER BY date, "ServiceName", "costcenter";
Actual vs amortized June cost per service, from two cost_query scans joined on ServiceName; amortization_shift (amortized − actual) shows where reservation/savings-plan purchases are spread out (largest absolute shift first; the date filter drops the restatement-lookback days each scan re-pulls)
WITH actual AS (SELECT "ServiceName", currency, sum(cost) AS actual_cost FROM azure.main.cost_query('subscriptions/<guid>', '2026-06-01', '2026-06-30', group_by := 'Dimension:ServiceName') WHERE _row_kind IS NULL AND date BETWEEN '2026-06-01' AND '2026-06-30' GROUP BY ALL), amortized AS (SELECT "ServiceName", currency, sum(cost) AS amortized_cost FROM azure.main.cost_query('subscriptions/<guid>', '2026-06-01', '2026-06-30', cost_type := 'AmortizedCost', group_by := 'Dimension:ServiceName') WHERE _row_kind IS NULL AND date BETWEEN '2026-06-01' AND '2026-06-30' GROUP BY ALL) SELECT "ServiceName", currency, round(coalesce(actual_cost, 0), 2) AS actual_cost, round(coalesce(amortized_cost, 0), 2) AS amortized_cost, round(coalesce(amortized_cost, 0) - coalesce(actual_cost, 0), 2) AS amortization_shift
FROM actual
FULL JOIN amortized USING ("ServiceName", currency)
ORDER BY abs(amortization_shift) DESC, "ServiceName";