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

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
stribor45
Post Prodigy
Post Prodigy

From DAX studio to Power BI DAX code

My code works fine in Dax Studio but when I move it to Power BI I have some trouble with it. Finally, I was able to change it and make it work but now having trouble with ORDER BY. I want to order the X table by ranking. Can someone help with this please. Also why on some pages it is  ORDERBY but somewhere it is ORDER BY.

 

https://dax.guide/orderby/

https://dax.guide/st/order-by/

 

MY TABLE = 


VAR T = 
        SUMMARIZECOLUMNS (
            'TABLEA'[COLUMN1],
            "REASON", COUNT ( 'TABLEA[COUNT] )
        )

VAR X = ADDCOLUMNS ( 
                   T, "Ranking", 
                   RANKX ( 
                         T, [REASON] 
                   )  
                
        ) 

        RETURN X

 

 

1 ACCEPTED SOLUTION
stribor45
Post Prodigy
Post Prodigy

I had this same problem while back and posted the question here 

Leason learned 🙂 look at your previous posts 🙂

View solution in original post

5 REPLIES 5
stribor45
Post Prodigy
Post Prodigy

I had this same problem while back and posted the question here 

Leason learned 🙂 look at your previous posts 🙂

Dangar332
Super User
Super User

Hi, @stribor45 

Use below

 

MY TABLE = 

 

VAR T = 

        SUMMARIZECOLUMNS (

            'TABLEA'[COLUMN1],

            "REASON", COUNT ( 'TABLEA[COUNT] )

        )

 

VAR X = ADDCOLUMNS ( 

                   T, "Ranking", 

                   RANKX ( 

                         T, [REASON] ,,asc

                   )  

                

        ) 

 

        RETURN X 

 

Use Asc or desc as your requirements 

 

And this  orderby use in window function like (offset, rank,window)

And this order by use outside of dax query to indicate order of any column or expression.

 

 

 

The dax code you shared but doesnt order based on REASON or Ranking. I would like this to be ordered by ranking if possible

hi, @stribor45 

use RANK instead of RANKX 

Yes i tried that but didnt work for me either. 

 

VAR X = ADDCOLUMNS(T, "Ranking",RANK (DENSE, T, ORDERBY ([REASON], ASC)))

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

Vote for your favorite vizzies from the Power BI World Championship submissions!

Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.