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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
Anonymous
Not applicable

Return second biggest value

Hi!

 

I am looking for a formula that will return the second biggest value. 

 

Below is the formula that is returning me the biggest value from a certain dataset:

 

LAstMonth = 
 CALCULATE(
 SUM(Q1_Subledger[Amount incl VAT]), 
 FILTER(Q1_Subledger,Q1_Subledger[Source.Name]=MAX(Q1_Subledger[Source.Name])
 ))

I am looking for something that will return the second biggest value... any idea? Name of the table is Q1_Subledger. So, from below dataset, I would like to have a sum of "Amount incl VAT" for 201903_6120.xlsx. And, when I add a set for 201905_6120.xlsx, I'd like the formula to pick 201904_6120 (so second biggest value).

 
Source.NameAmount incl VAT
201901_6120.xlsx5000
201901_6120.xlsx654
201901_6120.xlsx2001
201901_6120.xlsx225
201901_6120.xlsx23
201901_6120.xlsx5564
201901_6120.xlsx58797
201902_6120.xlsx46461
201902_6120.xlsx0
201902_6120.xlsx45468
201902_6120.xlsx645461
201902_6120.xlsx5456874
201902_6120.xlsx163546
201902_6120.xlsx500
201903_6120.xlsx600
201903_6120.xlsx987
201903_6120.xlsx415
201903_6120.xlsx525
201903_6120.xlsx858
201903_6120.xlsx747
201903_6120.xlsx969
201904_6120.xlsx636
201904_6120.xlsx302
201904_6120.xlsx301
201904_6120.xlsx201
201904_6120.xlsx502
 
 
thank you!
1 ACCEPTED SOLUTION
Zubair_Muhammad
Community Champion
Community Champion

@Anonymous 

 

Try following measure

 

SecondLAstMonth =
SUMX (
    TOPN (
        1,
        TOPN ( 2, VALUES ( Q1_Subledger[Source.Name] ), [Source.Name], DESC ),
        [Source.Name], ASC
    ),
    CALCULATE ( SUM ( Q1_Subledger[Amount incl VAT] ) )
)

View solution in original post

2 REPLIES 2
viniscera
New Member

Guy, you are amazing! I had solved my problem with your code! Thanks!

Zubair_Muhammad
Community Champion
Community Champion

@Anonymous 

 

Try following measure

 

SecondLAstMonth =
SUMX (
    TOPN (
        1,
        TOPN ( 2, VALUES ( Q1_Subledger[Source.Name] ), [Source.Name], DESC ),
        [Source.Name], ASC
    ),
    CALCULATE ( SUM ( Q1_Subledger[Amount incl VAT] ) )
)

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 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