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>] )
| Parameter | Type | Description |
|---|---|---|
from | Whole number | Where the window starts. |
from_type | Keyword 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. |
to | Whole number | Where the window ends; that row is in it. |
to_type | Keyword optional | REL (when left out) or ABS, as for from. |
relation or axis | Table 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. |
orderBy | ORDERBY optional | ORDERBY ( ... ): how the rows of each partition are ordered. Left out, by all the relation's columns, smallest first. |
blanks | Keyword optional | Where blank values go in the order: DEFAULT (or KEEP), the only choice here outside a visual calculation. |
partitionBy | PARTITIONBY optional | PARTITIONBY ( ... ): columns of the relation that split it into groups; the function stays inside the current row's group. |
matchBy | MATCHBY optional | MATCHBY ( ... ): the columns that identify the current row. Left out, all the relation's columns. |
reset | Reset 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
ABSevery row of the partition gets the same window. - In a visual calculation the relation can be an axis, as for
OFFSET;RANGEandMOVINGAVERAGEare 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] | Liters | Three-month average | So far |
|---|---|---|---|
| 2026-01-01 | 45549 | 45549 | 45549 |
| 2026-02-01 | 45985 | 45767 | 91534 |
| 2026-03-01 | 45109 | 45547.6666666667 | 136643 |
| 2026-04-01 | 48416 | 46503.3333333333 | 185059 |
| 2026-05-01 | 52329 | 48618 | 237388 |
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] |
|---|---|
| Pils | 38 |
| Cider | 52 |
| IPA | 64 |
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 |
|---|---|---|
| D | 20 | D A |
| A | 50 | D A B |
| B | 80 | A B C |
| C | 80 | B C |