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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
kpangelinan
Helper I
Helper I

Calculate Days Between Dates

New to Power BI and need help with calculating the # of days between two date columns. I tried creating a datediff column per other solutions, but that didn't work. Any other suggestions or tweaks to the formula?

 

Data Info:

Column 1: Created Date

Column 2: Executed Agreement Date

Capture.PNGNote - 

1 ACCEPTED SOLUTION
Sean
Community Champion
Community Champion

@kpangelinan

You must have end_dates that are prior to their corresponding start_dates!

Even if this happens only on one row in your entire dataset - you'll get this error!

Adjust your formula like this...

Days Column = 
SWITCH (
    TRUE (),
    'Table'[start_date] < 'Table'[end_date], DATEDIFF ( 'Table'[start_date], 'Table'[end_date], DAY ),
    'Table'[start_date] > 'Table'[end_date], DATEDIFF ( 'Table'[end_date], 'Table'[start_date], DAY ) * -1,
    0
)

You multiply * -1 to get negative numbers where the event ended before it started!

This way you'll be able to quickly identify any issues with your data indicated by the negative numbers.

Hope this helps! Smiley Happy

View solution in original post

3 REPLIES 3
Sean
Community Champion
Community Champion

@kpangelinan

You must have end_dates that are prior to their corresponding start_dates!

Even if this happens only on one row in your entire dataset - you'll get this error!

Adjust your formula like this...

Days Column = 
SWITCH (
    TRUE (),
    'Table'[start_date] < 'Table'[end_date], DATEDIFF ( 'Table'[start_date], 'Table'[end_date], DAY ),
    'Table'[start_date] > 'Table'[end_date], DATEDIFF ( 'Table'[end_date], 'Table'[start_date], DAY ) * -1,
    0
)

You multiply * -1 to get negative numbers where the event ended before it started!

This way you'll be able to quickly identify any issues with your data indicated by the negative numbers.

Hope this helps! Smiley Happy

Anonymous
Not applicable

what about getting the fractional number of days between two time columns, Power BI forces to round the numbers up.

 

Even when I get this difference in hours it rounds up when dividing on 24 to convert the difference in days not hours! 

 

Can you help me please?

 

Thank you @Sean! This worked and now I can easily idenify those records that have "executed" dates before a "created" dates. Thank you for the quick response.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.