Forum Discussion
Dax Measures
- 5 years ago
You can try below code.
Date_Diff =var calculate_diff = DATEDIFF(MAX('Dates_table'[Column A]),MAX('Dates_table'[Column B]),DAY)return IF(calculate_diff < 0,calculate_diff * -1,calculate_diff) - 5 years ago
You can create measure with below code to achive this
Date_Differences =VAR calculate_diff =DATEDIFF ( MAX ( 'Test'[Column A] ), TODAY(), DAY )RETURNIF (MAX ( 'Test'[Column A] ) <= TODAY ()&& MAX ( 'Test'[Column B] ) = DATE ( 1899, 12, 31 ),calculate_diff,FORMAT ( MAX ( 'Test'[Column B] ), "MM/DD/YYYY" ))PFA screenshot of output
You can try below code.
- peteru90675 years ago
Helper III
Thank you very much........ that worked perfectly well for me.
- peteru90675 years ago
Helper III
An extension to what I am actually trying to accomplish is calculating overdue dates for Compliance Testing. I can use calculated columns to get it done but I know there is probably a better way to use measures.
So with both columns Column A is Planned Date and Column B is Completed Date...... in my fact table if the test is yet to be performed column B is 12/31/1899. So if Planned date was 07/01/2021 and completed is 12/31/1899 that means the test is "overdue" by 11 days if counting today.
So here is what I think the code should be:
IF Column A <= today() && Column B = 12/31/1899, **some planned dates are in the future
Datediff = Column A, Column B
But what will the DAX Measure look like
- Samarth_185 years ago
Community Champion
You can create measure with below code to achive this
Date_Differences =VAR calculate_diff =DATEDIFF ( MAX ( 'Test'[Column A] ), TODAY(), DAY )RETURNIF (MAX ( 'Test'[Column A] ) <= TODAY ()&& MAX ( 'Test'[Column B] ) = DATE ( 1899, 12, 31 ),calculate_diff,FORMAT ( MAX ( 'Test'[Column B] ), "MM/DD/YYYY" ))PFA screenshot of output