Forum Discussion
Date Difference Calculation between dates
In Power BI, you can calculate the date difference between the Start Date and End Date columns, and then filter the result to only include days in 2022 and 2023. You can use the following steps to achieve this:
Create a Calculated Column: First, you'll need to create a calculated column that calculates the date difference between the Start Date and End Date columns. You can do this by using the DATEDIFF function. Assuming your table is named "YourTable," and the calculated column name is "DateDiff," the formula would look like this:
DateDiff = DATEDIFF(YourTable[Start Date], YourTable[End Date], DAY)
This formula calculates the difference between the Start Date and End Date in days.
Create a Filter: Next, you can create a filter to include only the days in 2022 and 2023. You can use a measure for this purpose. Create a new measure with the following formula:
DaysIn2022And2023 =
CALCULATE(
SUM(YourTable[DateDiff]),
FILTER(
YourTable,
YEAR(YourTable[Start Date]) IN {2022, 2023}
)
)
This measure sums the DateDiff column but filters it to only include rows where the Start Date year is 2022 or 2023.
Display the Result: Finally, you can display the "DaysIn2022And2023" measure in your Power BI report to see the total number of days in 2022 and 2023 for each row in your table.
Make sure to replace "YourTable," "Start Date," and "End Date" with the actual names of your table and columns in your Power BI dataset. This approach will give you the desired date difference calculation for the specified years.
If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly.