Skip to main content
On this page

Kater SQL Functions Calendar comparisons

KATER__PERIOD_SHIFT

The measure for the period a set number of steps before or after each row's period.

Family: Calendar comparisons

Syntax

KATER__PERIOD_SHIFT(measure, by => date, unit => unit, offset => integer [, coverage => 'matching_elapsed' | 'full_period'])

Arguments

Required

ArgumentDescription
measureThe measure to compare, written bare, without EVAL.
byThe date axis to compare along, such as KATER__MONTH(orders.order_date). You must name it. An expression.
unitThe length of one step. One of 'year', 'quarter', 'month', 'week', 'day'.
offsetHow many steps. A nonzero signed integer (negative looks backward, positive forward).

Optional

ArgumentDescription
coverageWhat the earlier period covers when the query filters the date axis. 'matching_elapsed' takes the same dates, moved back. 'full_period' takes whole periods. One of 'matching_elapsed', 'full_period'. It is 'matching_elapsed' when left out.

Returns

A number. The field menu writes the @format of the field it reads beside it, or @format number(2) where that field has none and can have decimals.

Usage notes

  • It works the measure out again over the source rows of the earlier period. It does not read an earlier row of the result, so a period with no row still has a value.
  • The unit fits the axis’s grain. A day axis takes any unit, a week axis takes week, a month axis takes month, quarter or year, a quarter axis takes quarter or year, and a year axis takes year.
  • A date filter on the axis needs fixed dates at both ends. A moving end, such as CURRENT_DATE, is refused.
  • For the change, subtract the call from EVAL(measure). For the percent change, give EVAL(measure) and the call to KATER__PERCENT_CHANGE.
  • In a query, declare it with CUSTOM_CALCULATION.

Example

This Sandbox query reads the sample shop’s orders. The table shows the rows that Kater gave.

SELECT
KATER__MONTH(orders.order_date) AS "Order Month",
EVAL(orders.sum__quantity) AS "Units",
CUSTOM_CALCULATION(
'period_shift__sum__quantity',
KATER__PERIOD_SHIFT(orders.sum__quantity, by => KATER__MONTH(orders.order_date), unit => 'month', offset => -3)
) AS "Units 3 Months Before"
FROM kater_dataset.orders AS orders
WHERE
KATER__IS_BETWEEN(orders.order_date, DATE '2026-05-01', DATE '2026-09-30')
GROUP BY
KATER__MONTH(orders.order_date)
ORDER BY
1
Order MonthUnitsUnits 3 Months Before
2026-05-01441388
2026-06-01403491
2026-07-01438374
2026-08-01454441
2026-09-01442403

See also