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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Krystyna
Regular Visitor

Rankx for every year

Hello Krystyna here

I am new in PowerBi world and I need some help with a RANKX function.

My data has only three columns:

ProductId, Year, Value

I need to rank products for every year. I created such measure

 

 

ProductRank = RANKX(ALL('Table'[Year]), CALCULATE(SUM('Table'[Value]), ALLEXCEPT('Table','Table'[Year])))

 

 

 But the result is 1 for every ProductId.

What am I doing wrong?

Thanks

K

1 ACCEPTED SOLUTION
v-jianboli-msft
Community Support
Community Support

Hi @Krystyna ,

 

Based on your description, I have created a simple sample:

vjianbolimsft_1-1669961142858.png

Please try:

Measure =
RANKX(ALLEXCEPT('Table','Table'[Year]),CALCULATE(SUM('Table'[Value]),FILTER(ALLEXCEPT('Table','Table'[Year]),[ID]=EARLIER('Table'[ID]))),SUM('Table'[Value]),,Dense)

Output:

vjianbolimsft_2-1669961182761.png

Best Regards,

Jianbo Li

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

8 REPLIES 8
v-jianboli-msft
Community Support
Community Support

Hi @Krystyna ,

 

Based on your description, I have created a simple sample:

vjianbolimsft_1-1669961142858.png

Please try:

Measure =
RANKX(ALLEXCEPT('Table','Table'[Year]),CALCULATE(SUM('Table'[Value]),FILTER(ALLEXCEPT('Table','Table'[Year]),[ID]=EARLIER('Table'[ID]))),SUM('Table'[Value]),,Dense)

Output:

vjianbolimsft_2-1669961182761.png

Best Regards,

Jianbo Li

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

 

 

 

For me, it created a circular dependance on [YEAR] and failed.

Hi Jianbo LI and thx for your help.

It works but only with Year column from this table. I use other table as a time dimension (only one column with year integer) and when I use this dimension it does not work. Could you give me a hint how should I change this measure formula? Or maybe should I add it as a column in the table rather than measure?

 

Thx in advance

Thennarasu_R
Responsive Resident
Responsive Resident

@Krystyna 
Hi,
Try This One 

ProductRank = RANKX(ALL('Table'[Year]), CALCULATE(SUM('Table'[Value]),,Desc)


Thanks ,
Thennarasu

 

Results:

Krystyna_0-1669284464943.png

 

Many doubled ranks when value is completely different

@Krystyna 
Rewrite Dax  Inside the ALL Functions Change column  to  Table 

Thanks,
thennarasu 

amitchandak
Super User
Super User

@Krystyna , Try like

 

ProductRank = RANKX(filter(ALL('Table'[Year], Table[Product]), Table[Year] = Max(Table[Year])), CALCULATE(SUM('Table'[Value])),,desc,dense)

 

 

Measure Rank: https://www.youtube.com/watch?v=DZb_6j6WuZ0&list=PLPaNVDMhUXGaaqV92SBD5X2hk3TMNlHhb&index=40


https://radacad.com/how-to-use-rankx-in-dax-part-2-of-3-calculated-measures

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

Still all are 1

Helpful resources

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

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.