cancel
Showing results for
Did you mean:
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. 😞

 Related ItemGroupID InvoiceAmt Sum Perc Ratio Itemgroup Sales Rank Measure Month EXTERNAL 57 2 Jan FOC 4 Jan METAL 15 3 Jan PLASTIC 28 2 Jan
1 ACCEPTED SOLUTION
Community Support

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:

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.

3 REPLIES 3
Community Support

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:

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.

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.

Features || Datamarts: https://youtu.be/8tskWsJTEpg || Field Parameters : https://youtu.be/lqF3Wa1FllE?t=70
Time Intelligence Decoded : https://youtu.be/aU2aKbnHuWs&t=145s || Learn 50+ Power Query List Functions
Did I answer your question? Mark my post as a solution! Appreciate your Kudos !! Proud to be a Super User! !!
Dashboard of My Blogs !! Connect on Linkedin !! Subscribe to my youtube Channel !!!! How to get Quick Help !!
Resources | Master Power BI !! Expertise Power BI !! Power BI For Tableau User !!
Frequent Visitor

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:

My desired output:

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. 😫

Announcements

#### CollabDays Lisbon - 26 November 2022

Sessions include practical, hands-on experience that will help you take the next step in your career and know-how.

#### Difinity Conference 2022

Difinity is the largest Microsoft Data, AI, Power BI, Power Platform and Business Applications Conference in New Zealand.

#### European Share Point Conference

This conference returns live and in-person in Copenhagen this 28 November-01 December with 4 Microsoft Keynotes, 9 Tutorials, and 120 Sessions.

#### Microsoft 365 Conference - 06-08 December

Join us in Las Vegas to experience community, incredible learning opportunities, and connections that will help grow skills, know-how, and more.

Top Solution Authors
Top Kudoed Authors