OpenBI Docs Buy

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>] )
ParameterTypeDescription
positionWhole numberWhich row: 1 the first, 2 the second, -1 the last, -2 the one before it.
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 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: without PARTITIONBY, 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]
IPA64
Lettøl30

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]LitersBest seller
Cider301074Pils
IPA331884Pils
Lettøl169179Pils
Pils1004326Pils

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)

OFFSET, WINDOW, TOPN, FIRST, LAST.

Last updated · OpenBI Studio 0.3.74