OpenBI Docs Buy

ROWNUMBER

The current row's number within its partition in an order, unique to it.

Group: Window and visual calculations. Compatible with DAX.

Syntax

ROWNUMBER ( [<relation or axis>] [, <orderBy>] [, <blanks>] [, <partitionBy>] [, <matchBy>] [, <reset>] )
ParameterTypeDescription
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: DEFAULT, FIRST or LAST, as for RANK.
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

Whole number. The current row's place in its partition: 1, 2, 3 ..., never shared.

Remarks

  • Unlike RANK, rows that tie in the order get different numbers: the relation's other columns decide between them.
  • Where the context leaves no single current row, as on a total, the result is BLANK.
  • Give the relation or leave it out; an empty first argument is an error.
  • As with RANK, the relation needs at least one model column, or must be a table the query defines.

Examples

Ties get their own numbers

DEFINE
    TABLE Shops =
        DATATABLE (
            "Shop", STRING, "Liters", INTEGER,
            { { "A", 50 }, { "B", 80 }, { "C", 80 }, { "D", 20 } }
        )
EVALUATE
ADDCOLUMNS (
    Shops,
    "Row", ROWNUMBER ( Shops, ORDERBY ( Shops[Liters], DESC ) ),
    "Rank", RANK ( SKIP, Shops, ORDERBY ( Shops[Liters], DESC ) )
)
ORDER BY [Row]
Shops[Shop]Shops[Liters]RowRank
B8011
C8021
A5033
D2044

Products numbered by liters sold

EVALUATE
ADDCOLUMNS (
    VALUES ( Products[Product] ),
    "Liters", [Liters sold],
    "Row", ROWNUMBER ( ALL ( Products[Product] ), ORDERBY ( [Liters sold], DESC ) )
)
ORDER BY [Row]
Products[Product]LitersRow
Pils10043261
IPA3318842
Cider3010743
Lettøl1691794

RANK, RANKX, INDEX, ORDERBY.

Last updated · OpenBI Studio 0.3.74