Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Redraidas10
Frequent Visitor

How to use 'ORDER BY' in DAX?

I have a very simple DAX script written, however, DAX engine seems to ignore 'ORDER BY' (as per screenshot below). Any idea how to force DAX engine to take ORDER BY into consideration?

EVALUATE
SUMMARIZECOLUMNS(
    'Table'[Year], 'Table'[Color],
    FILTER('Table', 'Table'[Year] = "2000"),
    "Sales Total", SUM('Table'[Sales])) 
ORDER BY 
      "Sales Total" DESC

 

 

Dax studio.JPG

 

1 ACCEPTED SOLUTION
jdbuchanan71
Super User
Super User

It needs to know how to handle the other columns.  You should also avoid putting FILTER over an entire table, just use the VALUES in the column(s) you want to filter.

EVALUATE
SUMMARIZECOLUMNS (
    'Table'[Year],
    'Table'[Color],
    FILTER ( VALUES ( 'Table'[Year] ), 'Table'[Year] = 2000 ),
    "Sales Total", SUM ( 'Table'[Sales] )
)
ORDER BY
    "Sales Total" DESC,
    'Table'[Color],
    'Table'[Year]

jdbuchanan71_0-1618089754525.png

 

View solution in original post

3 REPLIES 3
jdbuchanan71
Super User
Super User

No, you don't need to include them all every time.
https://docs.microsoft.com/en-us/dax/orderby-statement-dax

 

jdbuchanan71
Super User
Super User

It needs to know how to handle the other columns.  You should also avoid putting FILTER over an entire table, just use the VALUES in the column(s) you want to filter.

EVALUATE
SUMMARIZECOLUMNS (
    'Table'[Year],
    'Table'[Color],
    FILTER ( VALUES ( 'Table'[Year] ), 'Table'[Year] = 2000 ),
    "Sales Total", SUM ( 'Table'[Sales] )
)
ORDER BY
    "Sales Total" DESC,
    'Table'[Color],
    'Table'[Year]

jdbuchanan71_0-1618089754525.png

 

Nice example. Does it mean that for every "ORDER BY" clause, we have to explicitly mention all columns in that table?

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.