Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes! Register now.

Reply
peteru9067
Helper III
Helper III

Dax Measures

I am trying to write a dax measures for finding the number of dates between two dates in column A & B....... I do not want to add a calculated column but a dax measures that will perform the difference. I am using DATEDIFF but I cannot select the columns where the dates are I am assuming I need to use an aggregator or something, like calculate, max, min etc.

 

Column A = 06/20/2021

Column B = 05/24/2021

 

 

2 ACCEPTED SOLUTIONS
Samarth_18
Community Champion
Community Champion

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)
 
Samarth_18_0-1626097264490.png

 

 

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

View solution in original post

You can create measure with below code to achive this

 

Date_Differences =
VAR calculate_diff =
DATEDIFF ( MAX ( 'Test'[Column A] ), TODAY(), DAY )
RETURN
IF (
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
Samarth_18_0-1626106785222.png

 

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

View solution in original post

4 REPLIES 4
Samarth_18
Community Champion
Community Champion

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)
 
Samarth_18_0-1626097264490.png

 

 

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

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

You can create measure with below code to achive this

 

Date_Differences =
VAR calculate_diff =
DATEDIFF ( MAX ( 'Test'[Column A] ), TODAY(), DAY )
RETURN
IF (
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
Samarth_18_0-1626106785222.png

 

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

Thank you very much........ that worked perfectly well for me.

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.