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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Jeffrey_VC
Helper II
Helper II

Max funtion

Hello Community,


I'm a newbie who is interesting in Power Bi and the working of DAX.

Now I'm trying to get the penultimate record in a colum. Is there a function in DAX what can help me?

 

Please can anyone help me in achiving this measure.

 

Thanks,

Jeffrey

 

1 ACCEPTED SOLUTION
johnt75
Super User
Super User

If you have a unique column in the table, like an ID, then you could do something like

Penultimate value =
VAR maxID =
    MAX ( 'Table'[ID] )
VAR val =
    SELECTCOLUMNS (
        CALCULATETABLE ( TOPN ( 1, 'Table', 'Table'[ID] ), 'Table'[ID] < maxID ),
        "@val", 'Table'[Desired column]
    )
RETURN
    val

View solution in original post

4 REPLIES 4
colacan
Resolver II
Resolver II

Hi, You can filter out the row which has minium value then get the minimum value to find penultimate as below.

colacan_1-1660127947107.png

 

I hope this helps you. 

Thanks

 

 

Hi,

Thank you for your answer.

I have tried:

 

Penultimate =
var minscore = minx(all('Ledigingen uit Middleware'[Datum/tijd]),
        'Ledigingen uit Middleware'[Datum/tijd])
var penul_wo_min = FILTER('Ledigingen uit Middleware',
     'Ledigingen uit Middleware'[Datum/tijd] <> minscore)
return MINX(penul_wo_min,'Ledigingen uit Middleware'[Datum/tijd])
 
 
The result is not the Penultimate but the first in the dataset:
 
Jeffrey_VC_1-1660128890554.pngJeffrey_VC_2-1660128923642.png

And I need:

Jeffrey_VC_3-1660128949992.png

 

 

 

johnt75
Super User
Super User

If you have a unique column in the table, like an ID, then you could do something like

Penultimate value =
VAR maxID =
    MAX ( 'Table'[ID] )
VAR val =
    SELECTCOLUMNS (
        CALCULATETABLE ( TOPN ( 1, 'Table', 'Table'[ID] ), 'Table'[ID] < maxID ),
        "@val", 'Table'[Desired column]
    )
RETURN
    val

Hi Johnt75,

 

Yes that looks like a solution. Thnx!

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors