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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Anonymous
Not applicable

Get previous value of a row based on another column's row value

Hi, here is the context of my question :

 

I am working with alerts, status (Turned On or Off ) and timestamps along with other values that are not relevant to what I'm asking here,

So there is a column for the alerts, which can repeat themselves without being the exact same alert but with the same tag, and there is a column for the timestamps and status.

 

I want to be able to get the previous timestamp of the alerts when they were turned on based on when they appear turned off ( acknowledged by operator ). In that case, the correct timestamp would be the one associated with the last time that the alarm was turned on which could be pretty far in terms of rows.

 

This is for a measure that would indicate the duration between the unique alert being turned on and turned off.

 

I should also mention that the status is in TEXT and the alert tag is also in TEXT

 

Thank you very much!!

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi  @Anonymous ,

I created the data:

v-yangliu-msft_0-1622093023148.png

Here are the steps you can follow:

1. Create calculated column

group =
RANKX(FILTER('Table','Table'[alerts]=EARLIER('Table'[alerts])),'Table'[timestamps],,ASC)
time =
var _1=CALCULATE(MAX('Table'[timestamps]),FILTER(ALL('Table'),'Table'[group]=EARLIER('Table'[group])-1&&'Table'[alerts]=EARLIER('Table'[alerts])))
return
DATEDIFF(_1,[timestamps],HOUR)

2. Result:

v-yangliu-msft_1-1622093023153.png

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi  @Anonymous ,

I created the data:

v-yangliu-msft_0-1622093023148.png

Here are the steps you can follow:

1. Create calculated column

group =
RANKX(FILTER('Table','Table'[alerts]=EARLIER('Table'[alerts])),'Table'[timestamps],,ASC)
time =
var _1=CALCULATE(MAX('Table'[timestamps]),FILTER(ALL('Table'),'Table'[group]=EARLIER('Table'[group])-1&&'Table'[alerts]=EARLIER('Table'[alerts])))
return
DATEDIFF(_1,[timestamps],HOUR)

2. Result:

v-yangliu-msft_1-1622093023153.png

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Greg_Deckler
Community Champion
Community Champion

@Anonymous Check if this helps: See my article on Mean Time Between Failure (MTBF) which uses EARLIER: http://community.powerbi.com/t5/Community-Blog/Mean-Time-Between-Failure-MTBF-and-Power-BI/ba-p/339586.
The basic pattern is:
Column = 
  VAR __Current = [Value]
  VAR __PreviousDate = MAXX(FILTER('Table','Table'[Date] < EARLIER('Table'[Date])),[Date])

  VAR __Previous = MAXX(FILTER('Table',[Date]=__PreviousDate),[Value])
RETURN
  __Current - __Previous

 

If not, sample data would help tremendously. Sorry, having trouble following, can you post sample data as text and expected output?
Not really enough information to go on, please first check if your issue is a common issue listed here: https://community.powerbi.com/t5/Community-Blog/Before-You-Post-Read-This/ba-p/1116882

Also, please see this post regarding How to Get Your Question Answered Quickly: https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490

The most important parts are:
1. Sample data as text, use the table tool in the editing bar
2. Expected output from sample data
3. Explanation in words of how to get from 1. to 2.



Follow on LinkedIn
@ 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!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors