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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

Second top value

Hi,

 

Request your help to overcome this issue

 

From my table I could easily find out the Top position value by applying the MAX function but how can i get the second top value . It works when I use TOP N function in the Filter pane but i would like to get the same via DAX

 

awaiting your guidance

 

dsmitha

 

 

 

3 ACCEPTED SOLUTIONS
amitchandak
Super User
Super User

@Anonymous , Try these measures

Rankx = ankx(allselected(Table[Category]), [sales],,desc,dense)

You can use visual level filter Rank =2 (<category should be replaced with your rank column> should be in visual)

 

 

 

or create a measure on top of that

2nd Rank sumx(filter(values(Table[Category]), [Rank] =2), [Sales])

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

View solution in original post

Jihwan_Kim
Super User
Super User

Hi,

I am not sure how your data model looks like, but please check the below picture and the attached pbix file.

I tried to create a sample pbix file like below.

One of ways to check the second top value is, MAX function can be still utilized to find second top value when the first MAX value is filtered out.

 

Picture1.png

 

Value total: = 
SUM( Data[Value] )

 

Value first max: = 
VAR _condition =
    CALCULATE ( MAX ( Data[Value] ), ALL ( Data[Category] ) ) = [Value total:]
RETURN
    DIVIDE ( _condition, _condition ) * [Value total:]

 

Value second max: = 
VAR _condition =
    CALCULATE (
        MAX ( Data[Value] ),
        FILTER ( ALL ( Data[Category] ), [Value total:] <> [Value first max:] )
    ) = [Value total:]
RETURN
    DIVIDE ( _condition, _condition ) * [Value total:]

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

View solution in original post

Anonymous
Not applicable

Hi Jihwan_Kim,

 

excellent idea, this one also worked,  thanks a lot

 

View solution in original post

5 REPLIES 5
Jihwan_Kim
Super User
Super User

Hi,

I am not sure how your data model looks like, but please check the below picture and the attached pbix file.

I tried to create a sample pbix file like below.

One of ways to check the second top value is, MAX function can be still utilized to find second top value when the first MAX value is filtered out.

 

Picture1.png

 

Value total: = 
SUM( Data[Value] )

 

Value first max: = 
VAR _condition =
    CALCULATE ( MAX ( Data[Value] ), ALL ( Data[Category] ) ) = [Value total:]
RETURN
    DIVIDE ( _condition, _condition ) * [Value total:]

 

Value second max: = 
VAR _condition =
    CALCULATE (
        MAX ( Data[Value] ),
        FILTER ( ALL ( Data[Category] ), [Value total:] <> [Value first max:] )
    ) = [Value total:]
RETURN
    DIVIDE ( _condition, _condition ) * [Value total:]

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.
Anonymous
Not applicable

dsmitha_0-1649172031862.png

I got the visual as i wanted , thanks a lot 👍

Anonymous
Not applicable

Hi Jihwan_Kim,

 

excellent idea, this one also worked,  thanks a lot

 

amitchandak
Super User
Super User

@Anonymous , Try these measures

Rankx = ankx(allselected(Table[Category]), [sales],,desc,dense)

You can use visual level filter Rank =2 (<category should be replaced with your rank column> should be in visual)

 

 

 

or create a measure on top of that

2nd Rank sumx(filter(values(Table[Category]), [Rank] =2), [Sales])

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube
Anonymous
Not applicable

Hi amitchandak,

 

Thank you very much for your quick response

that one solved my issue

 

regards,

dsmitha

 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.