Forum Discussion
Newbie12345
2 years agoRegular Visitor
HELP!! DAX : Date Diff
Hi All, Please help me around with the below query. Topic: DAX Query: I want to calculate the date diff between 2 dates ( of each category) , attaching the screen-shot for your kind reference. ...
- 2 years ago
Newbie12345
Use this measure as a calculated column in your table and make sure to change the table name as per yours:Date Diff = VAR __MaxDate = CALCULATE( MAX( Table03[Date] ) , ALLEXCEPT(Table03 , Table03[ID] , Table03[Category] ) ) VAR __PrevDate = CALCULATE( MAX( Table03[Date] ) , Table03[Date] < __MaxDate, ALLEXCEPT(Table03 , Table03[ID] , Table03[Category] ) ) RETURN IF( Table03[Date] = __MaxDate && __PrevDate <> BLANK() ,INT (__MaxDate - __PrevDate ) ) - 2 years ago
Hi, Newbie12345
make a new column using below codeColumn = var a = 'Table'[date] var b = 'Table'[id] var c= 'Table'[category] var d = MAXX(FILTER('Table','Table'[date]<a && 'Table'[category]=c && 'Table'[id]=b),'Table'[date]) var e= IF(d=BLANK(),'Table'[date],d) var f= CONVERT('Table'[date]-e,INTEGER) return fjust adjust table and column name
Fowmy
2 years agoSuper User
Newbie12345
Use this measure as a calculated column in your table and make sure to change the table name as per yours:
Date Diff =
VAR __MaxDate =
CALCULATE(
MAX( Table03[Date] ) ,
ALLEXCEPT(Table03 , Table03[ID] , Table03[Category] )
)
VAR __PrevDate =
CALCULATE(
MAX( Table03[Date] ) ,
Table03[Date] < __MaxDate,
ALLEXCEPT(Table03 , Table03[ID] , Table03[Category] )
)
RETURN
IF( Table03[Date] = __MaxDate && __PrevDate <> BLANK() ,INT (__MaxDate - __PrevDate ) )