Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateJoin us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.
Hello,
I have a table that looks like this (Please note that my date is in the format DD/MM/YYYY):
I want to calculate the difference between two following dates where condition=1.
I managed to create the column in orange with the following DAX code:
datediff = IF( Table[condition]=1, Table[date] - CALCULATE( SUM(Table[date]), FILTER( Table[index] = EARLIER(Table[index])-1 ) ), BLANK() )
But I want to get the values in the yellow column. Can you help me achieve this without having to create a new index column?
Thank you
Solved! Go to Solution.
Hi @Unknown
You can use
datediff =
VAR CurrentDate = 'Table'[date]
VAR PreviousTable =
FILTER (
'Table',
'Table'[date] < CurrentDate
&& 'Table'[condition] <> BLANK ()
)
VAR PreviousDate =
MAXX ( PreviousTable, 'Table'[date] )
RETURN
IF (
'Table'[condition] = 1
&& NOT ISEMPTY ( PreviousTable ),
DATEDIFF ( PreviousDate, CurrentDate, DAY )
)
Hi @Unknown
You can use
datediff =
VAR CurrentDate = 'Table'[date]
VAR PreviousTable =
FILTER (
'Table',
'Table'[date] < CurrentDate
&& 'Table'[condition] <> BLANK ()
)
VAR PreviousDate =
MAXX ( PreviousTable, 'Table'[date] )
RETURN
IF (
'Table'[condition] = 1
&& NOT ISEMPTY ( PreviousTable ),
DATEDIFF ( PreviousDate, CurrentDate, DAY )
)
User | Count |
---|---|
14 | |
9 | |
7 | |
7 | |
6 |
User | Count |
---|---|
22 | |
11 | |
10 | |
10 | |
8 |