Forum Discussion
Days between multiple dates
- 11 months ago
I named the table Fact
Created a key calc column
key = 'Fact'[Order Date] & 'Fact'[Product]DAX code of the calc column Delta Days
Delta Days =VAR keyRow = 'Fact'[key]VAR Prevkey = MAXX ( FILTER ( VALUES( 'Fact'[key] ), 'Fact'[key] < keyRow ), 'Fact'[key] )VAR PrevDate = CALCULATE( SELECTEDVALUE( 'Fact'[Order Date] ), 'Fact'[key] = Prevkey, REMOVEFILTERS() )RETURNIF (NOT ISBLANK( Prevkey ),INT('Fact'[Order Date] - PrevDate))If this helped, please consider giving kudos and mark as a solution
mein replies or I'll lose your threadWant to check your DAX skills? Answer my biweekly DAX challenges on the kubisco Linkedin page
Consider voting this Power BI idea
Francesco Bergamaschi
MBA, M.Eng, M.Econ, Professor of BI
- 11 months ago
Days Between =
VAR CurrentDate = 'Table'[Order Date]
VAR PrevDate =
CALCULATE (
MAX ( 'Table'[Order Date] ),
FILTER (
'Table',
'Table'[Product] = EARLIER ( 'Table'[Product] )
&& 'Table'[Order Date] < EARLIER ( 'Table'[Order Date] )
)
)
RETURN
IF ( ISBLANK ( PrevDate ), 0, DATEDIFF ( PrevDate, CurrentDate, DAY ) )
Days Between =
VAR CurrentDate = 'Table'[Order Date]
VAR PrevDate =
CALCULATE (
MAX ( 'Table'[Order Date] ),
FILTER (
'Table',
'Table'[Product] = EARLIER ( 'Table'[Product] )
&& 'Table'[Order Date] < EARLIER ( 'Table'[Order Date] )
)
)
RETURN
IF ( ISBLANK ( PrevDate ), 0, DATEDIFF ( PrevDate, CurrentDate, DAY ) )
Thank you so much, this worked perfectly!! Much appreciated 💪