Join us at FabCon Atlanta from March 16 - 20, 2026, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.
Register now!Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote 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 )
)
Vote for your favorite vizzies from the Power BI World Championship submissions!
If you love stickers, then you will definitely want to check out our Community Sticker Challenge!
Check out the January 2026 Power BI update to learn about new features.
| User | Count |
|---|---|
| 8 | |
| 6 | |
| 3 | |
| 3 | |
| 3 |
| User | Count |
|---|---|
| 19 | |
| 12 | |
| 11 | |
| 6 | |
| 6 |