cancel
Showing results for
Did you mean:
Frequent Visitor

## 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!

1 ACCEPTED SOLUTION
Super User

@leone1857 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/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

Become an expert!: Enterprise DNA
External Tools: MSHGQM
Latest book!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...
Super User

@leone1857 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/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

Become an expert!: Enterprise DNA
External Tools: MSHGQM
Latest book!:
Mastering Power BI 2nd Edition

DAX is easy, CALCULATE makes DAX hard...

Announcements