ORDER BY DAX Statement
The ORDER BY keyword is part of the EVALUATE statement and defines the sort order of the result produced by EVALUATE.
It can include only columns that are part of EVALUATE or expressions that can be computed in the row context of the result.
Every column can be sorted in an ascending (ASC) or descending (DESC) way. The default is ASC.
EVALUATE
ALL (
'Product'[Brand],
'Product'[Color]
)
ORDER BY
'Product'[Brand] ASC,
'Product'[Color] DESC
The ORDER BY keyword can be also used to identify the sort order of an axis in a visual shape for visual calculations.
Find more in Introducing VISUAL SHAPE for visual calculations in Power BI.
The following example shows an example of a visual shape definition in a DAX query.
TABLE '__DS0VisualCalcs' = __DS0VisualCalcsInput
WITH VISUAL SHAPE
AXIS ROWS
GROUP [Brand]
TOTAL [IsGrandTotalRowTotal]
GROUP
[Category],
[Category_Code]
TOTAL [IsDM1Total]
GROUP [Color]
TOTAL [IsDM3Total]
ORDER BY
[Brand] ASC,
[Category_Code] ASC,
[Category] ASC,
[Color] ASC
AXIS COLUMNS
GROUP [Year]
TOTAL [IsGrandTotalColumnTotal]
GROUP
[Month],
[Month_Number]
TOTAL [IsDM6Total]
ORDER BY
[Year] ASC,
[Month_Number] ASC,
[Month] ASC
DENSIFY "IsDensifiedRow"
Last update: Mar 8, 2024 » Contribute » Show contributors
Contributors: Alberto Ferrari, Marco Russo, Daniil Maslyuk
Microsoft documentation: https://docs.microsoft.com/en-us/dax/orderby-statement-dax
