DATEDIFF DAX Function in Power BI
The DATEDIFF DAX function in Power BI returns the number of interval boundaries between two dates.
DAX Syntax DATEDIFF(start_date, end_date, interval)
The function has the following parameters:
- start_date: The starting date (column, measure, or expression).
- end_date: The ending date.
- interval: The unit of time to calculate the difference.
We can use the following keywords for interval:
Interval | Description |
---|---|
SECOND | Difference in seconds |
MINUTE | Difference in minutes |
HOUR | Difference in hours |
DAY | Difference in days |
WEEK | Difference in weeks |
MONTH | Difference in months |
QUARTER | Difference in quarters |
YEAR | Difference in years |
Example: Calculate the Difference in Year.
DAX
DATEDIFF Measure = DATEDIFF( DATE(2022, 4, 12), DATE(2025, 6, 25), YEAR )
The output of the above code is 3.
Example: Calculate the Difference in Quarter.
DAX
DATEDIFF Measure = DATEDIFF( DATE(2022, 4, 12), DATE(2025, 6, 25), QUARTER )
The output of the above code is 12.
Example: Calculate the Difference in Months.
DAX
DATEDIFF Measure = DATEDIFF( DATE(2022, 4, 12), DATE(2025, 6, 25), MONTHS )
The output of the above code is 38.
Note: • If end_date is earlier than start_date, result will be negative.
• Works with columns and measures.
Example: Calculate the Difference in Months, this time the result is -38.
DAX
DATEDIFF Measure = DATEDIFF( DATE(2025, 6, 25), DATE(2022, 4, 12), MONTHS )
The output of the above code is -38.