Forum Discussion
Calculate Days Between Dates
- 9 years ago
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! :smileyhappy:
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! :smileyhappy:
- kpangelinan9 years agoHelper I
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.
- Anonymous8 years agoNot 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?