OpenBI Docs Buy

ORDERBY

In a window function, the expressions, and their directions, that order each partition.

Group: Window and visual calculations. Compatible with DAX.

Syntax

ORDERBY ( <orderBy_expression> [, <order>] [, <orderBy_expression> [, <order>]] … )
ParameterTypeDescription
orderBy_expressionExpression
repeatable, evaluated for each row
A value worked out for each row of the relation: a column, or an expression such as a measure.
orderKeyword
optional, repeatable
ASC (when left out) for smallest first, DESC for largest first; 1 or TRUE, 0 or FALSE say the same.

Returns

None. It gives no value of its own: it tells the window function around it how to order the rows.

Remarks

  • It goes only inside OFFSET, INDEX, WINDOW, RANK, ROWNUMBER and the visual calculation functions; anywhere else it is an error.
  • Each expression may have its own direction; the second decides between rows the first leaves tied.
  • A measure in it is evaluated for each row of the relation, so ORDERBY ( [Liters sold], DESC ) orders products by their own sales.
  • Left out of a window function, the order is by all the relation's columns, smallest first.

Examples

By category, then dearest first

EVALUATE
ADDCOLUMNS (
    ALL ( Products[Category], Products[Product], Products[Price per liter] ),
    "Row",
        ROWNUMBER (
            ALL ( Products[Category], Products[Product], Products[Price per liter] ),
            ORDERBY ( Products[Category], ASC, Products[Price per liter], DESC )
        )
)
ORDER BY [Row]
Products[Category]Products[Product]Products[Price per liter]Row
BeerIPA641
BeerPils382
BeerLettøl303
CiderCider524

A number for the direction

0 is DESC: the largest first.

DEFINE
    TABLE Shops =
        DATATABLE (
            "Shop", STRING, "Liters", INTEGER,
            { { "A", 50 }, { "B", 80 }, { "C", 80 }, { "D", 20 } }
        )
EVALUATE
ADDCOLUMNS (
    Shops,
    "Rank", RANK ( DENSE, Shops, ORDERBY ( Shops[Liters], 0 ) )
)
ORDER BY Shops[Shop]
Shops[Shop]Shops[Liters]Rank
A502
B801
C801
D203

PARTITIONBY, MATCHBY, RANK, OFFSET, WINDOW.

Last updated · OpenBI Studio 0.3.74