INDEX
The row at a position in the current row's partition, in an order (1 the first, -1 the last).
Group: Window and visual calculations. Compatible with DAX.
Syntax
INDEX ( <position> [, <relation or axis>] [, <orderBy>] [, <blanks>] [, <partitionBy>] [, <matchBy>] [, <reset>] )
| Parameter | Type | Description |
|---|---|---|
position | Whole number | Which row: 1 the first, 2 the second, -1 the last, -2 the one before it. |
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 row at that place of the current row's partition.
Remarks
- A position of 0, a blank, or one beyond the partition's rows gives an empty table.
- Unlike
OFFSET, the place does not depend on the current row, only the partition does: withoutPARTITIONBY, every row gets the same answer. - Left out, the relation is the selected values of the ORDERBY columns, and the order is by all the relation's columns.
CALCULATE ( SELECTEDVALUE ( Products[Product] ), INDEX ( 1, ... ) )gives the name of the first row.
Examples
The dearest and the cheapest product
EVALUATE
UNION (
INDEX ( 1, ALL ( Products[Product], Products[Price per liter] ), ORDERBY ( Products[Price per liter], DESC ) ),
INDEX ( -1, ALL ( Products[Product], Products[Price per liter] ), ORDERBY ( Products[Price per liter], DESC ) )
)
| Products[Product] | Products[Price per liter] |
|---|---|
| IPA | 64 |
| Lettøl | 30 |
The best seller beside every product
EVALUATE
SUMMARIZECOLUMNS (
Products[Product],
"Liters", [Liters sold],
"Best seller",
CALCULATE (
SELECTEDVALUE ( Products[Product] ),
INDEX ( 1, ALL ( Products[Product] ), ORDERBY ( [Liters sold], DESC ) )
)
)
ORDER BY Products[Product]
| Products[Product] | Liters | Best seller |
|---|---|---|
| Cider | 301074 | Pils |
| IPA | 331884 | Pils |
| Lettøl | 169179 | Pils |
| Pils | 1004326 | Pils |
A position past the end
There are four products: the fifth is an empty table, and its count is blank.
EVALUATE
ROW ( "Rows", COUNTROWS ( INDEX ( 5, ALL ( Products[Product] ), ORDERBY ( Products[Product] ) ) ) )
| Rows |
|---|
| (blank) |