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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Anonymous
Not applicable

How can i get the second highest ou lowest value?

Hi,

 

I have a process that returns several date/time values for tha same control number. For example:

 

row     number   date/time

1         1234        24/08/2020 10:12

2         1234        24/08/2020 11:25

3         1234        24/08/2020 11:48

4         1234        24/08/2020 12:36

 

I need a measure that recognizes the oldest and the econd oldest value for the same control number and calculate the diferrence between then. In this case they are in the rows number 1 (oldest) and 2 (second oldest) and the diference is 01:13 (it can be in minutes too, 01:13 = 73 minutes).

 

1 ACCEPTED SOLUTION
ryan_mayu
Super User
Super User

@Anonymous 

Please try this

Measure = 
VAR _MIN=MIN('Table'[date/time])
VAR _SECMIN=MINX(FILTER('Table','Table'[date/time]>_MIN),'Table'[date/time])
RETURN DATEDIFF(_MIN,_SECMIN,MINUTE)

1.PNG





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




View solution in original post

3 REPLIES 3
Fowmy
Super User
Super User

@Anonymous 


Try this measure please:

Difference = 
VAR _MIN = 
    CALCULATE(
        MIN(CONTROL[Date]),
        ALLEXCEPT(CONTROL,CONTROL[Number])
    )

VAR _MIN2 = 
    CALCULATE(
        MIN(CONTROL[Date]),
        CONTROL[Date] > _MIN,
        ALLEXCEPT(CONTROL,CONTROL[Number]))    
RETURN
DATEDIFF(
    _MIN,
    _MIN2,
    MINUTE
)

 

________________________

Did I answer your question? Mark this post as a solution, this will help others!.

Click on the Thumbs-Up icon if you like this reply 🙂

YouTube, LinkedIn

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

ryan_mayu
Super User
Super User

@Anonymous 

Please try this

Measure = 
VAR _MIN=MIN('Table'[date/time])
VAR _SECMIN=MINX(FILTER('Table','Table'[date/time]>_MIN),'Table'[date/time])
RETURN DATEDIFF(_MIN,_SECMIN,MINUTE)

1.PNG





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




amitchandak
Super User
Super User

@Anonymous , Try like

datediff(maxx(filter(table,[number] =earlier([number]) && [row] =earlier([row])-1 ),[date/time]), [date/time],minute)

 

Assumption row number continous

 

 

Full Power BI Video 20 Hours YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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