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

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

Reply
Zain26
Advocate II
Advocate II

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 )
)

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 )
)

@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 )

 

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors
Top Kudoed Authors