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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
vamsi_tiger
Frequent Visitor

get nth largest value based on other column

i have a table as below

datereasonduration
23/6breakdown5
24/6snacks10
22/6breakdown2
21/6shutdown50
21/6other1
24/6other2
24/6break5

so if the select the time slicer on the page to 21 to 24 it should filter the values in the table to that time line and aggregate the duration of that perticualar reason and sort is as per the total duration and give me the reason. 
so lets say i need 2nd largest reason with respect to selected duration(eample 21-24 considering total table as above) the measure should give me "snacks" since it has 10 min
@power @PowerBI @PBCommunity 

 

1 ACCEPTED SOLUTION
tamerj1
Super User
Super User

Hi @vamsi_tiger 
Please refer to attached sample file with the proposed solution

1.png2.png

nth Largest Reason = 
MAXX ( 
    TOPN (
        1,
        TOPN ( 
            SELECTEDVALUE ( 'nth Largest'[n] ),
            SUMMARIZE ( 
                'Table',
                'Table'[reason],
                "@Duration", SUM ( 'Table'[duration] )
            ),
            [@Duration]
        ),
        [@Duration],
        ASC
    ),
    'Table'[reason]
)
Title = 
VAR n = SELECTEDVALUE ( 'nth Largest'[n] )
RETURN
    n & SWITCH ( n, 1, "st", 2, "nd", 3, "rd", "th" ) & " Largest Reson"

View solution in original post

2 REPLIES 2
vamsi_tiger
Frequent Visitor

This is way easy than the dax i wrote. Thanks a lot

tamerj1
Super User
Super User

Hi @vamsi_tiger 
Please refer to attached sample file with the proposed solution

1.png2.png

nth Largest Reason = 
MAXX ( 
    TOPN (
        1,
        TOPN ( 
            SELECTEDVALUE ( 'nth Largest'[n] ),
            SUMMARIZE ( 
                'Table',
                'Table'[reason],
                "@Duration", SUM ( 'Table'[duration] )
            ),
            [@Duration]
        ),
        [@Duration],
        ASC
    ),
    'Table'[reason]
)
Title = 
VAR n = SELECTEDVALUE ( 'nth Largest'[n] )
RETURN
    n & SWITCH ( n, 1, "st", 2, "nd", 3, "rd", "th" ) & " Largest Reson"

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.