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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
keithchai
Frequent Visitor

RANKX Is ranking on my total which is weird

So I has got a Fact table and had a measure to calculate the monthly sales ratio by a category group. 

 

Next I wanted to know the rank from highest to lowest ratio for the particular category but below is the ranking that I got from this DAX formula : 

Rank = RANKX( ALLEXCEPT( FactInvoice , NHFCalendar[Month] ) , CALCULATE( [InvoiceAmt Sum Perc] , ALLEXCEPT( FactInvoice , FactInvoice[Related ItemGroupID], NHFCalendar[Month])), , DESC, Dense)
 
Problem I face is why is the ranking is 1 for the total and not on "External category" instead? And the reason the rank 2 gets duplicated ? I am really lost any guidance would highly appreciated. 😞
 
 

pbi_help.PNG

 

 

 

Related ItemGroupIDInvoiceAmt Sum PercRatio Itemgroup Sales RankMeasureMonth
EXTERNAL572 Jan
FOC 4 Jan
METAL153 Jan
PLASTIC282 Jan
1 ACCEPTED SOLUTION
v-cazheng-msft
Community Support
Community Support

Hi @keithchai 

You can create a Measure to get the result you want.

 

Rank =

VAR res =

    RANKX (

        ALLEXCEPT ( FactInvoice, FactInvoice[Month] ),

        CALCULATE (

            [InvoiceAmt Sum Perc],

            ALLEXCEPT ( FactInvoice, FactInvoice[Related ItemGroupID], FactInvoice[Month] )

        ),

        ,

        DESC,

        DENSE

    )

RETURN

    IF ( HASONEFILTER ( FactInvoice[Related ItemGroupID] ), res, BLANK () )

 

The result looks like this:

v-cazheng-msft_0-1616228842939.png

Best Regards

Caiyun Zheng

 

Is that the answer you're looking for? If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

View solution in original post

3 REPLIES 3
v-cazheng-msft
Community Support
Community Support

Hi @keithchai 

You can create a Measure to get the result you want.

 

Rank =

VAR res =

    RANKX (

        ALLEXCEPT ( FactInvoice, FactInvoice[Month] ),

        CALCULATE (

            [InvoiceAmt Sum Perc],

            ALLEXCEPT ( FactInvoice, FactInvoice[Related ItemGroupID], FactInvoice[Month] )

        ),

        ,

        DESC,

        DENSE

    )

RETURN

    IF ( HASONEFILTER ( FactInvoice[Related ItemGroupID] ), res, BLANK () )

 

The result looks like this:

v-cazheng-msft_0-1616228842939.png

Best Regards

Caiyun Zheng

 

Is that the answer you're looking for? If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

amitchandak
Super User
Super User

@keithchai , what is your base data, what was shown in the last table ?

Try like

Rank = RANKX( ALLselected(FactInvoice ) , CALCULATE( [InvoiceAmt Sum Perc] , ALLEXCEPT( FactInvoice , FactInvoice[Related ItemGroupID], NHFCalendar[Month])), , DESC, Dense)

 

Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data.

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Hi @amitchandak ,

I tried changed to ALLSELECTED the result is not desired. 

The rank now is ranking on the entire year, I only wanted to know the rank for the categories within the month. 

ALLSELECTED Result:

pbi_help.PNG

 

My desired output:

pbi_help.PNG

 

My base data is just a simple fact invoice table, with the sales amount for the invoices throughout the year. 

InvoiceAmt Sum Perc is the percentage of invoiceamt sum for the month. Say January is 57% of the total sales and 58% for March total sales etc. If possible I may not want to share the pbix file, my company is a little strict. 😫

 

pbi_help.PNG

 

 

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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