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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch 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

 

 

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

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!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.