# DATEDIFF

## What is the DATEDIFF Function?

The DATEDIFF function is a DAX function (Data Analysis Expressions) that calculates the difference between two dates. It returns the number of intervals (days, months, years, etc.) between two given dates.

## Syntax of the DATEDIFF Function

The syntax of the DATEDIFF function is as follows:

DATEDIFF(❰interval❱,❰startdate❱,❰enddate❱)

``` - **interval**: The type of date interval you want to use (e.g. "day", "month", "year", etc.) - **startdate**: The start date of the interval - **enddate**: The end date of the interval Example Usage of the DATEDIFF Function Let's say you have a table with two columns: "Order Date" and "Ship Date". You want to calculate the number of days it took to ship each order. Here's how you can use the DATEDIFF function to do that: ```

Days to Ship = DATEDIFF(“day”,[Order Date],[Ship Date])

``` This will create a new column in your table called "Days to Ship" which will contain the number of days between the Order Date and Ship Date for each row. Using the DATEDIFF Function with Other DAX Functions The DATEDIFF function can also be used in combination with other DAX functions to create more complex calculations. For example, you can use it with the DATEADD function to calculate the end date of a project based on the start date and duration: ```

Project End Date = DATEADD([Start Date], [Duration],”day”)

``` You can also use it with the IF function to create conditional calculations based on the time interval: ```

Late Delivery = IF(DATEDIFF(“day”,[Order Date],[Ship Date]) ❱ [Expected Delivery Date],”Yes”,”No”)

``` This will create a new column in your table called "Late Delivery" which will contain a "Yes" or "No" value based on whether the order was shipped after the expected delivery date. The DATEDIFF function is a powerful tool for analyzing and comparing dates in your Power BI reports. It can be used in a variety of ways to create simple or complex calculations depending on your needs. By mastering the DATEDIFF function, you'll be well on your way to creating more insightful and actionable reports in Power BI. Power BI DAX Training Courses by G Com Solutions (0800 998 9248) Power BI DAX Intensive Training Course £1,260.00 – £31,860.00 Select optionsContinue Loading Done Power BI DAX Introduction £474.00 – £11,700.00 Select optionsContinue Loading Done Power BI DAX Intermediate £474.00 – £11,700.00 Select optionsContinue Loading Done Power BI DAX Advanced £474.00 – £11,700.00 Select optionsContinue Loading Done Upcoming Courses 16-18 September 202411-13 November 2024 Contact Us Subject Your Name (required) Company/Organisation Email (required) Telephone Training Course(s) Power BI Intensive TrainingPower BI introduction Power BI IntermediatePower BI AdvancedDAXPower Query MPower BI CertificationPower BI AdministrationPower PlatformPower AutomatePower AppsOTHER Your Message Upload Example Document(s) (Zip multiple files) ```
``` ```
``` ```
``` ```
``` ```
``` ```