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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
EglanVer
New Member

Request for help with RANKX function (DAX measure)

Hi everyone,

I am facing an issue with the RANKX DAX. Can anyone help me please?

 

The table in the screenshot below should display the quantity of each brand purchased. There are 153 brands that i need to rank and the RANKX function needs to rank the lowest as 1, assign any dublicate "Share of Quantity" values the same number and then skip to the next ranking. 

 

Here are the DAX functions I used for the displayed columns:

  • Share of quantity = [Quantity purchased] / [Total quantity]

  • ROUND = ROUND(CALCULATE(([Quantity purchased] / [Total quantity]) * 100), 1)

  • RANK_FINAL = RANKX(ALL(APRIL_2024_PURCHASES[BRANDS]), [ROUND], [ROUND], ASC, Skip)

The ROUND function was an alternative attempt, as the "Share of quantity" function didn't seem to work. 

 

As you can see in the screenshot below, you'll notice that the ranking jumps from "1" to "13" instead of continuing to 6. How is this possible? What do you think could be the error? I've looked so many times on Microsoft Learn and YouTube and still couldn't fix it... 😓 Could you please help? Thanks in advance!🙏

EglanVer_0-1739958279732.png

 

1 ACCEPTED SOLUTION
DataInsights
Super User
Super User

@EglanVer,

 

Try this measure using the RANK function. It's preferred over RANKX in most cases.

 

RANK_FINAL =
VAR SourceTable =
    ADDCOLUMNS (
        ALLSELECTED ( APRIL_2024_PURCHASES[BRANDS] ),
        "@ShareOfQuantity", [Share of quantity]
    )
VAR Result =
    RANK ( DENSE, SourceTable, ORDERBY ( [@ShareOfQuantity], ASC ) )
RETURN
    Result

 

https://www.sqlbi.com/articles/introducing-the-rank-window-function-in-dax/  





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

3 REPLIES 3
EglanVer
New Member

OMG! It works now. 😄 Thank you so much @DataInsights  for your help and time 🙏

@EglanVer,

 

Glad to hear it works!





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




DataInsights
Super User
Super User

@EglanVer,

 

Try this measure using the RANK function. It's preferred over RANKX in most cases.

 

RANK_FINAL =
VAR SourceTable =
    ADDCOLUMNS (
        ALLSELECTED ( APRIL_2024_PURCHASES[BRANDS] ),
        "@ShareOfQuantity", [Share of quantity]
    )
VAR Result =
    RANK ( DENSE, SourceTable, ORDERBY ( [@ShareOfQuantity], ASC ) )
RETURN
    Result

 

https://www.sqlbi.com/articles/introducing-the-rank-window-function-in-dax/  





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.