OpenBI Docs Buy

WINDOW

The rows from one position to another in the current row's partition, each position counted from the current row or from an end of the partition.

Group: Window and visual calculations. Compatible with DAX.

Syntax

WINDOW ( <from> [, <from_type>], <to> [, <to_type>] [, <relation or axis>] [, <orderBy>] [, <blanks>] [, <partitionBy>] [, <matchBy>] [, <reset>] )
ParameterTypeDescription
fromWhole numberWhere the window starts.
from_typeKeyword
optional
REL (when left out): from counts from the current row, negative back; ABS: from is a place in the partition, 1 the first, -1 the last.
toWhole numberWhere the window ends; that row is in it.
to_typeKeyword
optional
REL (when left out) or ABS, as for from.
relation or axisTable
optional
The rows it works among: a table of the model or one the query defines. Left out, the values the ORDERBY and PARTITIONBY columns have in the selection (as ALLSELECTED gives them). In a visual calculation, an axis such as ROWS instead.
orderByORDERBY
optional
ORDERBY ( ... ): how the rows of each partition are ordered. Left out, by all the relation's columns, smallest first.
blanksKeyword
optional
Where blank values go in the order: DEFAULT (or KEEP), the only choice here outside a visual calculation.
partitionByPARTITIONBY
optional
PARTITIONBY ( ... ): columns of the relation that split it into groups; the function stays inside the current row's group.
matchByMATCHBY
optional
MATCHBY ( ... ): the columns that identify the current row. Left out, all the relation's columns.
resetReset
optional
In a visual calculation only: where the count starts again, as for PREVIOUS.

Returns

Table. The relation's rows from the start to the end of the window, both included.

Remarks

  • WINDOW ( -2, REL, 0, REL, ... ) is the current row and the two before it: a three-row moving window.
  • WINDOW ( 1, ABS, 0, REL, ... ) runs from the first row to the current one: a running total, year to date within a partition by year.
  • The window is cut at the partition's edges; when it starts after it ends, or lies wholly outside, it is empty.
  • With both ends ABS every row of the partition gets the same window.
  • In a visual calculation the relation can be an axis, as for OFFSET; RANGE and MOVINGAVERAGE are the shortcuts there.

Examples

A moving average and a running total

EVALUATE
SUMMARIZECOLUMNS (
    Sales[Month],
    FILTER ( ALL ( Sales[Month] ), YEAR ( Sales[Month] ) = 2026 && MONTH ( Sales[Month] ) <= 5 ),
    "Liters", [Liters sold],
    "Three-month average",
        AVERAGEX ( WINDOW ( -2, REL, 0, REL, ALLSELECTED ( Sales[Month] ), ORDERBY ( Sales[Month] ) ), [Liters sold] ),
    "So far",
        CALCULATE ( [Liters sold], WINDOW ( 1, ABS, 0, REL, ALLSELECTED ( Sales[Month] ), ORDERBY ( Sales[Month] ) ) )
)
ORDER BY Sales[Month]
Sales[Month]LitersThree-month averageSo far
2026-01-01455494554945549
2026-02-01459854576791534
2026-03-014510945547.6666666667136643
2026-04-014841646503.3333333333185059
2026-05-015232948618237388

Places 2 to the last, by price

EVALUATE
WINDOW (
    2, ABS,
    -1, ABS,
    ALL ( Products[Product], Products[Price per liter] ),
    ORDERBY ( Products[Price per liter], ASC )
)
ORDER BY Products[Price per liter]
Products[Product]Products[Price per liter]
Pils38
Cider52
IPA64

Neighbours on a table the query defines

Types left out are REL: the shop before, the shop itself and the one after, in order of liters.

DEFINE
    TABLE Shops =
        DATATABLE (
            "Shop", STRING, "Liters", INTEGER,
            { { "A", 50 }, { "B", 80 }, { "C", 80 }, { "D", 20 } }
        )
EVALUATE
ADDCOLUMNS (
    Shops,
    "Neighbours",
        CONCATENATEX ( WINDOW ( -1, 1, Shops, ORDERBY ( Shops[Liters] ) ), Shops[Shop], " " )
)
ORDER BY Shops[Liters], Shops[Shop]
Shops[Shop]Shops[Liters]Neighbours
D20D A
A50D A B
B80A B C
C80B C

OFFSET, INDEX, RANGE, MOVINGAVERAGE, AVERAGEX.

Last updated · OpenBI Studio 0.3.74