Syntax
DATEDIFF(<start_date>, <end_date>, <interval>)
Learn with examples!
Let me demonstrate how DATEDIFF work using different real scenarios:
Example1: Calculate the difference between two dates in Power BI
In today’s video, I will show you how to calculate the difference between two dates using DATEDIFF.
I also show you how to overcome the issue when the start date is larger than the end date.
Links to the mentioned resources
To get the files:
1. Go to Curbal Download Center > Dax Fridays
2. Get File #17
Example2: Deconstruct a DAX measure
In today’s video we will deconstruct a measure that was created by a Microsoft employee in the Power BI community:
Link to the Power BI community post: https://community.powerbi.com/t5/Desktop/Calculate-duration-based-on-dates-in-different-rows/td-p/58886
In this video we will go also through the functions:
05:56 LOOKUPVALUE
09:12 DATEDIFF
Links to the mentioned resources
To get the files:
1. Go to Curbal Download Center > Dax Fridays
2. Get File #54
Example 3: Calculate the difference between two dates in the same column in Power BI
Do you know how to calculate the difference between dates when both are in the same column?
One example of when this is needed is when you are working with subscription based services. If you want to calculate how many dates go between users changing subscriptions, this DAX measure will help you.
Links to the mentioned resources
To get the files:
1. Go to Curbal Download Center > Dax Fridays
2. Get File #85
Example 4: Create a relative week filter in Power BI
When the custom date filter in Power BI doesn’t do what you need, how you create your own? What if you need to do it by week?
Links to the mentioned resources
To get the files:
1. Go to Curbal Download Center > Dax Fridays
2. Get File #131
Remarks
An error is returned if start_date is larger than end_date.
Leave a Reply