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
Ngh25
Regular Visitor

Ranking a table based on 2 dynamic selected years using Max function

Hello @Ashish_Mathur 

I am trying to rank my Operations table based on 1 or more dynamic years chosen by the user from my Year slicer. 
This is my Operations table based on 2023 selection : 

Lab;Date;Nb_test; Rank;Rank Y-1
France;2023;5000;1;2
US;2023;602;4;5
INDIA;2023;1200;3;4

CHINA;2023;4300;2;1
BRAZIL;2023;338;5;3

2022 selection :

 

France;2022;4271;2;2
US;2022;708;5;5
INDIA;2022;2437;4;3

CHINA;2022;4980;1;1
BRAZIL;2022;2600;3;4


I want to create a measure that ensures both of the cases ( 1 or 2 selected values) and calculates the max value between both of the selected years then does the ranking this way : 

LabLims request creation dateMax (Nb tests [2023 - 2022])Max (Nb tests [2022 - 2021])Ranking [2023 - 2022]Ranking [2022 - 2021]
France[2023 - 2022]132301076311
US[2023 - 2022]9302894922
INDIA[2023 - 2022]7680732443
CHINA[2023 - 2022]6002600255
BRAZIL[2023 - 2022]8338636634

 

If anyone has a recommendation on how to achieve it, please feel free to comment below 🙂 
Thanks !

 

 
4 REPLIES 4
Ngh25
Regular Visitor

Hi @v-xinruzhu-msft  again and thank you for your answer !
1-Nb test is a measure not a column so I can"t use it directly this way! 
2- I don't see the filter on the date range here, it's only taking the max value of nb tests but the filtrer doesn't work. I did it this way : 

Max_value = CALCULATE(MAX(Nb_tests),ALLSELECTED('Operations'),'Operations'[lab] in VALUES ('Operations'[lab]))
Rank = RANKX(ALLSELECTED('Operations'[lab]),[Max_value],,DESC)
I need to use he date column from Operations based on the selected values of the calandar slicer, but I can"t achieve it correctly ! with 1 parameter it work successfully, but here, it doesn't !
Ngh25
Regular Visitor

Hi @v-xinruzhu-msft ! 
thank you for your answer but it doesn't work for me! 
The issue here, is that I am  working in direct query mode, so I can't add tables or more links in the data model, the only way I have is to do it by creating a measure! 

Hi @Ngh25 

It will not affect it, if you cannot create the table, you can use the measures I offered directly, it can work.

Max_value = CALCULATE(MAX('Table'[Nb_test]),ALLSELECTED('Table'),'Table'[Lab] in VALUES('Table'[Lab]))
Rank = RANKX(ALLSELECTED('Table'[Lab]),[Max_value],,DESC)

Output

vxinruzhumsft_0-1714438814866.png

 

Best Regards!

Yolo Zhu

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

 

v-xinruzhu-msft
Community Support
Community Support

Hi @Ngh25 

You can refer to the following sample.

Sample data 

vxinruzhumsft_0-1714358141248.png

1.You can create a year table, then create a relationship between tables.

vxinruzhumsft_1-1714358188619.png

vxinruzhumsft_2-1714358215625.png

 

2.Create a max measure

Max_value =
CALCULATE (
    MAX ( 'Table'[Nb_test] ),
    ALLSELECTED ( 'Table' ),
    'Table'[Lab] IN VALUES ( 'Table'[Lab] )
)

3.Create a rank measure

Rank = RANKX(ALLSELECTED('Table'[Lab]),[Max_value],,DESC)

4.Put the following fields to matrix

vxinruzhumsft_3-1714358310226.png

 

Output

vxinruzhumsft_4-1714358332033.png

 

Best Regards!

Yolo Zhu

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

 

 

 

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.

Top Solution Authors