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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
jobf
Helper II
Helper II

Difference between several dates in the same column

Hello. I need to calculate the difference between several dates in the same column. For example:

Field Date
P101/01/2024
P101/03/2024
P101/06/2024
P101/11/2024
P202/02/2024
P202/09/2024
P202/16/2024
P202/20/2024


I need to calculate the difference between a date and the date before it in the same field. If there is no previous date, the value must be 0. The final table must be like this:

Field Date Difference
P101/01/2024 0
P101/03/2024 2
P101/06/2024 3
P101/11/2024 5
P202/02/2024 0
P202/09/2024 7
P202/16/2024 7
P202/20/2024 4
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @jobf 

 

Thanks for the reply from @samratpbi .

 

@jobf , you can try the following measure:

Difference = 
VAR _Previous = MAX('Table'[Date])
VAR _PreviousRowDate = 
    CALCULATE(
        MAX('Table'[Date]),
        FILTER(
            ALLEXCEPT('Table', 'Table'[Field]),
            'Table'[Date] < _Previous
        )
    )
RETURN
    IF(
        ISBLANK(_PreviousRowDate),
        0,
        MAX([Date]) - _PreviousRowDate
    )

 

Output:

vxuxinyimsft_0-1721638410204.png

 

Best Regards,
Yulia Xu

 

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

View solution in original post

4 REPLIES 4
samratpbi
Super User
Super User

Hi, in addition, just noticed you are resetting the calculation based on the field. Hence little modification on the previous calculation which should be like below:

Versus previous =
IF(
    [Field ] <> PREVIOUS([Field ]),
    0,
    IF(
        PREVIOUS([Date]) = BLANK(), 0,
    [Date] - PREVIOUS([Date])
    )
)
 
If this helps to resolves your problem, then please mark it as solution, Thanks
samratpbi
Super User
Super User

Hi, there are many ways, however I think the easiest way is to use newly introduced visual level calculation.

Its under Home -> New Calculation.

samratpbi_1-1721331872431.png

 

I have loaded your data and created the below calculation as New Calculation:

samratpbi_0-1721331811873.png

 

If this helps to resolve your problem, then please mark it as solution provided. Thanks

Dont forget to give kudos 🙂

 

Is there a way to do this without the PREVIOUS function?

Anonymous
Not applicable

Hi @jobf 

 

Thanks for the reply from @samratpbi .

 

@jobf , you can try the following measure:

Difference = 
VAR _Previous = MAX('Table'[Date])
VAR _PreviousRowDate = 
    CALCULATE(
        MAX('Table'[Date]),
        FILTER(
            ALLEXCEPT('Table', 'Table'[Field]),
            'Table'[Date] < _Previous
        )
    )
RETURN
    IF(
        ISBLANK(_PreviousRowDate),
        0,
        MAX([Date]) - _PreviousRowDate
    )

 

Output:

vxuxinyimsft_0-1721638410204.png

 

Best Regards,
Yulia Xu

 

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

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.