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
Zain26
Helper I
Helper I

Second and Third Maximum Amount and Corresponding Text

Hello All,

  

Bit inexperienced with PowerBI, I am trying to calculate the Max, 2ndMax and 3rdMax amount based on the following columns. I want the Max of Sum of Amount for each Mapping, then I intend to print out the text against which I have calculated the Max and 2ndMax values as well in separate Card Visuals. 

Mapping      Amount
Alpha             10
Alpha             30
Beta               20
Beta               50
Alpha             40
Gamma          25
Gamma          50

 

The following query gave me the Max Amount for a Mapping i.e. 80 (Alpha)

Var maxAmount= MAXX(CALCULATETABLE(VALUES(table[Mapping]),ALLEXCEPT( table,table[Mapping])),CALCULATE(SUM(table[Amount])))

I want to get 75 as the second Max value since Gamma is 50+25 and 70 as the third Max as Beta has 50 and 20 as Amount, 
After this I want to get the corresponding Mapping values i.e. Alpha, Beta, Gamma in separate card visuals which is why i guess this will be done using separate measure. 
ANy help will be appreciated

1 ACCEPTED SOLUTION
Zubair_Muhammad
Community Champion
Community Champion

Hi @Zain26

 

First define a MEASURE to RANK the Mapping Values..

 

RANK =
RANKX (
    ALLSELECTED ( Table1[Mapping] ),
    CALCULATE ( SUM ( Table1[Amount] ) ),
    ,
    desc,
    DENSE
)

Now you can get the 1st , 2nd and 3rd mapping values as

 

FirstMappingValue =
CALCULATE (
    MAX ( Table1[Mapping] ),
    FILTER ( ALLSELECTED ( Table1[Mapping] ), [RANK] = 1 )
)
SecondMappingValue =
CALCULATE (
    MAX ( Table1[Mapping] ),
    FILTER ( ALLSELECTED ( Table1[Mapping] ), [RANK] = 2 )
)

Regards
Zubair

Please try my custom visuals

View solution in original post

3 REPLIES 3
questions
Helper I
Helper I

@Zubair_Muhammad 

 

Thanks, below is very clear.

 

However, I would like to further develop an visual to identify the weekly trend for the 2nd top mapping in different weeks by Region eg. Gamma. in Asia region in Week 1, 2 & 3

 

I try to put the rank into the visual level filter and choose the value as "2", but the graph didnt reponse accordingly.

 

Would you please explain 1) How to rank by the criteria by region & Week 2)develop the weekly trend for the 2nd top mapping?

Photo.png

 

summary:

Rank.png

Zubair_Muhammad
Community Champion
Community Champion

Hi @Zain26

 

First define a MEASURE to RANK the Mapping Values..

 

RANK =
RANKX (
    ALLSELECTED ( Table1[Mapping] ),
    CALCULATE ( SUM ( Table1[Amount] ) ),
    ,
    desc,
    DENSE
)

Now you can get the 1st , 2nd and 3rd mapping values as

 

FirstMappingValue =
CALCULATE (
    MAX ( Table1[Mapping] ),
    FILTER ( ALLSELECTED ( Table1[Mapping] ), [RANK] = 1 )
)
SecondMappingValue =
CALCULATE (
    MAX ( Table1[Mapping] ),
    FILTER ( ALLSELECTED ( Table1[Mapping] ), [RANK] = 2 )
)

Regards
Zubair

Please try my custom visuals

@Zain26

 

And you can get 2nd and 3rd Maximum Amounts using this pattern

 

File attached as well

 

Second Max Amount =
VAR secondMapping = [SecondMappingValue]
RETURN
    CALCULATE ( SUM ( Table1[Amount] ), Table1[Mapping] = secondMapping )

 


Regards
Zubair

Please try my custom visuals

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.