Skip to main content
A window measure applies a SQL window function to another measure, such as a running total, a rank within a group, a moving average, or the value from a previous row. You can build a window measure in a workbook, or in the model IDE using the window parameter.

Requirements

To create or edit a window measure in a workbook, you need Restricted Querier, Querier, Modeler, or Connection Admin permissions.

Creating a window measure

Window functions apply to measures only.
  1. In the field browser of a query tab, hover over a measure and click the icon that appears.
  2. Select Modeling > New window function.
Hover over an existing window measure and click the icon, then select Edit or Duplicate. Duplicating appends “Copy” to the field’s label and _copy to its field name.
Both options open the window measure drawer.

Choosing a function

By default, the drawer’s Function section is in Pick mode. Use the dropdown to choose a function. The descriptions use two terms:
  • A partition is a group of rows that the function treats as a separate set. The function starts over in each partition. See Partition by and order by.
  • A frame is the set of rows around the current row that the function calculates over. See Setting the frame.
Most functions apply to another measure — use the Measure field to choose it. Previous value and Next value also take a Rows back or forward count, for how many rows to look away from the current one.

Writing SQL directly

If the function you need isn’t available in Pick mode — for example, an expression over more than one measure — switch the toggle to Write SQL. This opens a SQL editor for the expression, without its OVER clause; partition, order, and frame stay configured separately, as described below. Switching back to Pick keeps your hand-written SQL as written. The SQL only changes if you then make a change in Pick mode, which rewrites it to match.

Partition by and order by

Partition by and Order by are shared by both Pick and Write SQL modes:
  • Partition by: the dimensions that split rows into separate groups, called partitions. The window function restarts in each partition.
  • Order by: the dimensions or measures that sort rows within each partition. Add multiple sort fields, and toggle each one between Asc and Desc.

Setting the frame

The frame is the set of rows the function uses to calculate the value for each row. It moves with the current row and stays inside the current partition. Frame start and Frame end set where the frame begins and ends, relative to the current row: First row, Rows preceding, Current row, Rows following, or Last row. For example, with a sum ordered by month: After you set Frame start or Frame end, a Rows/Range toggle appears. Rows counts rows. Range counts values of the single Order by field, so rows that share a value share a frame. The frame doesn’t apply to Rank, Dense rank, Row number, Previous value, or Next value, so the drawer hides it for those functions.

Next steps