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
Anonymous
Not applicable

RANKX issue

Hi all,

 

Got an issue with RANKX.

Here is my data model :

 

1 Fact table : Sales

2 dimensions tables : Calendar, stores

 

I want to create a measure to have store's rank over turnover.

 

I created measure Indicateurs[CA TTC] : SUM('Daily Sales N'[MNT_TTC]) => Sum(TurnOver)

And finally my RANKX = rankx(all(Stores),Indicateurs[CA TTC],,DESC)
 

Here is the result :

 
 
 
 
 
 
 
 
 
 

 

1 ACCEPTED SOLUTION

Hi @Anonymous ,

 

You can use the following  measure in your table visual:

 

Rang CA BU Mois Filtre = var a = SUMMARIZE(ALL(Stores),Stores[Magasin],"CA TTC",[CA TTC Mois],"rank",RANKX(ALL(Stores),CALCULATE([CA TTC Mois],ALLEXCEPT(Stores,Stores[Magasin])),,DESC)) return SUMX(FILTER(a,Stores[Magasin] = MAX(Stores[Magasin])),[rank])

 

Capture.PNG

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Best Regards,

Dedmon Dai

View solution in original post

14 REPLIES 14
amitchandak
Super User
Super User

@Anonymous , Measure rank is context-sensitive. You create a Rank on store, It will rank store or store rank inside other group by

 

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

For Rank Refer these links
https://radacad.com/how-to-use-rankx-in-dax-part-2-of-3-calculated-measures
https://radacad.com/how-to-use-rankx-in-dax-part-1-of-3-calculated-columns
https://radacad.com/how-to-use-rankx-in-dax-part-3-of-3-the-finale
https://community.powerbi.com/t5/Community-Blog/Dynamic-TopN-made-easy-with-What-If-Parameter/ba-p/367415

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
Anonymous
Not applicable

I modified my pbix, so i can send it. (70Mo)

How can i send it to you ?

You could give me your @ by private message ?

Hi @Anonymous ,

 

Would you please try to use the following rankx measure for it:

RANKX = RANKX(ALL('Stores'[magasin]),CALCULATE(SUM('Daily Sales N'[MNT_TTC])),,DESC)

If it dosen't work, would you please try to show us some sample data just contain these three table by onedrive for business?

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Best Regards,

Dedmon Dai

Anonymous
Not applicable

Hi,

 

My problem is still here.

Here are samples of data :

jlizzul_0-1601537038363.png

 

My joins are :

(1) STORES.RK_ETT = SALES.FK_ETT (n)

(1) CALENDAR.DAT_REF = SALES.DAT_VTE (n)

 

If you want the pbix, can you give me your @, so i can give you access to my drive

 

Regards,

Julien

Hi @Anonymous ,

 

Would you please show us sample pbix by onedrive for business?

 

Best Regards,

Dedmon Dai

Anonymous
Not applicable

Hi @Anonymous ,

 

Please check the permission for it.

 

Best Regards,

Dedmon Dai

Anonymous
Not applicable

Hi @Anonymous ,

 

Is the screenshot below you want?

 

Capture2.PNG

 

Please refer to the measure:

 

Rang CA BU Mois Filtre = if(HASONEVALUE(Stores[Magasin]),rankx(all(Stores[Magasin]),[CA TTC Mois],,DESC),0)

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Best Regards,

Dedmon Dai

 

Anonymous
Not applicable

This rank works fine in this table without any filter.

But if i try to filter on Bordeaux for example, i need to have the rank over all the stores : it should be 3.

The rank when i filter is 1.

Hi @Anonymous ,

 

You can use the following  measure in your table visual:

 

Rang CA BU Mois Filtre = var a = SUMMARIZE(ALL(Stores),Stores[Magasin],"CA TTC",[CA TTC Mois],"rank",RANKX(ALL(Stores),CALCULATE([CA TTC Mois],ALLEXCEPT(Stores,Stores[Magasin])),,DESC)) return SUMX(FILTER(a,Stores[Magasin] = MAX(Stores[Magasin])),[rank])

 

Capture.PNG

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Best Regards,

Dedmon Dai

Anonymous
Not applicable

@v-deddai1-msft

Thank you for your reactivity and your expertise.

 

I still have to do some tests to make sure everything is ok, but it seems to be working.

 

Just one question, is it normal to have to apply such a complex formula for a simple rank ?

 

Thanks again

Hi @Anonymous ,

 

As far as I concerned, Rankx measure the hard part in dax to understand. You can learn more about it by link provided by amitchandak. Maybe it's not the best way, but it's the best way I can write.

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Best Regards,

Dedmon Dai

 

Anonymous
Not applicable

Result.JPGDataModel.JPG

Helpful resources

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