Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
Mohan128256
Helper III
Helper III

Calculate Datediff if the dates are continuous

Hello All,

 

I have below dates,

Snapshot Date
4-16-2024
4-11-2024
4-10-2024
4-8-2024
4-5-2024
4-4-2024
4-3-2024
3-27-2024
3-22-2024
3-21-2024
3-20-2024
3-19-2024
3-18-2024

 

Here i would like to calcaulte the date diffierence with the previous date values if the dates are continous otherwise the calculation should start over.

 

The result that i am expecting is as follows.

 

Mohan128256_0-1713884114207.png

 

Any help with dax please.

 

Thanks,

Mohan V.

2 REPLIES 2
Mohan128256
Helper III
Helper III

@v-nuoc-msft thanks for the reply.

the result which i am expecting is not what you have got from the solution which you given here.

 

Here is the result which i am expecting where I should have the datediff with incremental 1 till it is continious.

If the dates are not continous then it should start over.

Expected result.

Mohan128256_0-1713942355900.png

 

Give output:

 

Mohan128256_1-1713942369133.png

 

Please help.

 

Thanks,

Mohan V.

 

v-nuoc-msft
Community Support
Community Support

Hi @Mohan128256 

 

For your question, here is the method I provided:

 

Here's some dummy data

 

"Table"

vnuocmsft_0-1713925393947.png

 

First, click Transform data to enter the Power Query interface and add a index column to the table.

 

vnuocmsft_2-1713925616827.png

 

Create a measure. When the current date is consecutive, the difference between the current date and the previous date is calculated.

 

Date Difference = 
VAR CurrentDate = SELECTEDVALUE('Table'[Snapshot Date])
VAR PreviousDate = CALCULATE(MAX('Table'[Snapshot Date]), FILTER(ALL('Table'), 'Table'[Snapshot Date] < CurrentDate))
var _date = CALCULATE(MAX('Table'[Snapshot Date]), FILTER(ALL('Table'), 'Table'[Index] = MAX('Table'[Index]) -1 ))
RETURN
IF(DATEDIFF(PreviousDate, CurrentDate, DAY) = 1, DATEDIFF(CurrentDate, _date, DAY), 0)

 

Here is the result.

 

vnuocmsft_3-1713925810076.png

 

Regards,

Nono Chen

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.