cancel
Showing results for 
Search instead for 
Did you mean: 

Fabric is Generally Available. Browse Fabric Presentations. Work towards your Fabric certification with the Cloud Skills Challenge.

Reply
BIswajit_Das
Helper V
Helper V

Power bi DAX findout 2nd MAX value

Hello Guys,
I have a table like

itemresa
1a30.98
1b30.98
1c20.34
1d

17.7

and
my required table is like

itemresamax2ndgap
1a30.9830.9830.980
1b30.9830.9830.980
1c20.3430.9830.980
1d17.730.9830.980

when i calculated its hard to detect max cause both a and b have same values so the coming 2nd max result is wrong
i.e the coming result is like

itemresamax2ndgap
1a30.9830.9820.3410.64
1b30.9830.9820.3410.64
1c20.3430.9820.3410.64
1d17.730.9820.3410.64

 

Thanks & Regrads...

4 REPLIES 4
BIswajit_Das
Helper V
Helper V

Hello @Ahmedx thanks for responding but

my required result table should like

itemresamax2ndgap
1a30.9830.9830.980
1b30.9830.9830.980
1c20.3430.9830.980
1d17.730.9830.980
Greg_Deckler
Super User
Super User

@BIswajit_Das Try:

max a 2nd = 
    VAR __Item = MAX('Table'[item])
    VAR __Table = FILTER(ALL('Table'), [item] = __Item)
    VAR __Summarized = SUMMARIZE(__Table, [item], [a], "__Count", COUNTROWS('Table'))
    VAR __Max = MAXX(__Table, [a])
    VAR __Result = 
        IF(
            MAXX(FILTER(__Summarized, [a] = __Max),[__Count]) > 1,
            __Max,
            MAXX(FILTER(__Summarized, [a] < __Max), [a])
        )
RETURN
    __Result

@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...

Hello @Greg_Deckler  Thanks for responding but what if i have multiple Items
i.e

itemresamax2ndgap
1a30.9830.9830.980
1b30.9830.9830.980
1c20.3430.9830.980
1d17.730.9830.980
2a55554510
2b45554510
3a35653530
3c65653530
Ahmedx
Super User
Super User

Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.

Power bi DAX findout 2nd MAX value.pbix

Helpful resources

Announcements
PBI November 2023 Update Carousel

Power BI Monthly Update - November 2023

Check out the November 2023 Power BI update to learn about new features.

Community News

Fabric Community News unified experience

Read the latest Fabric Community announcements, including updates on Power BI, Synapse, Data Factory and Data Activator.

Dashboard in a day with date

Exclusive opportunity for Women!

Join us for a free, hands-on Microsoft workshop led by women trainers for women where you will learn how to build a Dashboard in a Day!

Power BI Fabric Summit Carousel

The largest Power BI and Fabric virtual conference

130+ sessions, 130+ speakers, Product managers, MVPs, and experts. All about Power BI and Fabric. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors