Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
Hi,
I'm trying to build a measure (called Time Diff) that compares two consecutive rows, in this case the rows in the Time column. As shown in the column on the far right, I want the output to be in seconds, i.e. between row 1 and 2 it's 36 seconds, between row 2 and row 3 it's 53 seconds and so on.
If possible, I want to achieve this result by using a measure, not a calculated column. I've read about how to solve similar problems by creating a calcualted column using the EARLIER function.
Thanks in advance!
/Ella
Solved! Go to Solution.
@ellac create this measure:
Time Diff =
VAR _current_time = SELECTEDVALUE('Table'[Time])
VAR _previous_time =
MAXX(
FILTER(
ALL('Table'),
'Table'[Time] < _current_time
),
'Table'[Time]
)
VAR _result = (_current_time - _previous_time) * 86400
RETURN
IF(
NOT ISBLANK(_previous_time),
_result
)
@ellac 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/3395....
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
@ellac create this measure:
Time Diff =
VAR _current_time = SELECTEDVALUE('Table'[Time])
VAR _previous_time =
MAXX(
FILTER(
ALL('Table'),
'Table'[Time] < _current_time
),
'Table'[Time]
)
VAR _result = (_current_time - _previous_time) * 86400
RETURN
IF(
NOT ISBLANK(_previous_time),
_result
)
Thanks for your answer! Almost there... 🙂 _previous_time returns _current_time - 1 sec, i.e. the previous timestamp. For example _previous_time for Time 07:06:13 becomes 07:06:12.
Solved it! Just replaced the ALL function with ALLSELECTED. Thanks for your help @SpartaBI 🙂
@ellac my pleasure 🙂
Check out my showcase report - got some high level stuff there. Sure you will find there a lot of cool ideas.
https://community.powerbi.com/t5/Data-Stories-Gallery/SpartaBI-Feat-Contoso-100K/td-p/2449543
Give it a thumbs up over there if you liked it 🙂
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
110 | |
94 | |
82 | |
66 | |
58 |
User | Count |
---|---|
151 | |
121 | |
104 | |
87 | |
67 |