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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
AnthonyJoseph
Resolver III
Resolver III

top 4 categories based on a measure from another table

Hello Community,

 

I have been struggling with a calculation for past few days. Hoping someone could help here.

 

I have two tables (table 1 and table 2) and I want to find the top 4 categories for the latest/maximum year selected from year (multi-select) slicer from table 1 along with its value for the yers selected.

 

For example: if I select years 2022,2021 and 2020 the visual should display the top 4 categories for 2022 (based on a measure) and the categories corresponding value for 2021and 2020 as well.


The visual should not show any category that is not in top 4 for the year 2022. 

Measure:

 

Measure = 
var s = sum(Table1[Local movement]) 
return 
if(s <> 0, sum(Table1[Charge]) / s, s)

 

 

Table 1:

Temp IDCountryYearChargeLocal movement
1India20201000
2United Kingdom202020020
3United States20221300
6India20211140
7United Kingdom20211980
8United States20223400
10India202215187
11United kingdom20201460
12United States202114213

 

Table 2:

Temp IDCategoryTR
1Bike10
1Car20
1Scooter30
1Bicycle19
1Bicycle21
6Bike50
6Car30
6Scooter20
6Auto30
6Auto31
10Bike10
10Car30
10Scooter22
10Bicycle22
10Auto11
2Bike10
2Car20
2Scooter30
2Bicycle19
2Bicycle21
7Bike31
7Car87
7Scooter81
7Auto47
3Auto34
3Bike73
3Car74
3Scooter67
12Bike10
12Car100
12Scooter25
12Bicycle29
12Bike61
12Car68

 

Any help on this is really appreciated.

 

2 REPLIES 2
tamerj1
Super User
Super User

Hi @AnthonyJoseph 
Here is a sample file file with the solution https://we.tl/t-kKIBIDqOE5
Place this measure in the filter pane of the visual

Filter = 
VAR LastYearVisible = CALCULATE ( MAX ( Table1[Year] ), ALLSELECTED () )
RETURN
    RANKX ( 
        CROSSJOIN ( ALL ( Table1[Year] ), ALL ( Table2[Category] ) ),
        CALCULATE ( [Measure], Table1[Year] = LastYearVisible ),
        ,, Dense
    )

1.png

Thanks @tamerj1 . Is there any way we can sort the column in  graph in descending order of the rank?

 

Thanks,

Anthony Joseph

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors