Forum Discussion
DAX: Calculation based on having the same column value
Hi community,
I am stuck at the following. I want to obtain the time difference in seconds between rows based on a rank and the same column value in DAX.
This is my data:
I want to obtain the time difference in seconds between a rank and it's previous rank, whilst having the same club_id.
The result would look like this:
I tried to do it kinda like this answer, but without success. It would be nice to understand the DAX behind getting data with the same column values.
Thanks in advance for any help, tips or tricks!
Anonymous Use this:
seconds = VAR __clubID = [club_id] VAR __rank = [rank_team] VAR __previous = MAXX(FILTER('Table',[club_id] = __clubID && [rank_team] < __rank),[joined_at]) RETURN IF( __previous = BLANK(), 0, ROUND( ( [joined_at] - __previous ) * 1. * 24 * 60 * 60, 0) )PBIX is attached below signature. For a full explanation: 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
1 Reply
- Greg_DecklerCommunity Champion
Anonymous Use this:
seconds = VAR __clubID = [club_id] VAR __rank = [rank_team] VAR __previous = MAXX(FILTER('Table',[club_id] = __clubID && [rank_team] < __rank),[joined_at]) RETURN IF( __previous = BLANK(), 0, ROUND( ( [joined_at] - __previous ) * 1. * 24 * 60 * 60, 0) )PBIX is attached below signature. For a full explanation: 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