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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

calculate Difference from previous date

Good day,

 

Can anyone help me to get below output column in DAX. 
I want to calculate difference between values columns based on Dates column

 

nameDATESVALUESoutput
A08-12-2019 04:0025 
A09-12-2019 04:001025
A10-12-2019 04:001510
A11-12-2019 04:001015
A12-12-2019 04:00510
A13-12-2019 04:0065
A14-12-2019 04:00546
A15-12-2019 04:006554
B08-12-2019 04:0022 
B09-12-2019 04:004722
B10-12-2019 04:005147
B11-12-2019 04:002851
B12-12-2019 04:006428
B13-12-2019 04:008564
B14-12-2019 04:001685
C08-12-2019 04:0091 
C09-12-2019 04:002291
C10-12-2019 04:005222
C11-12-2019 04:008252
C12-12-2019 04:007582
C13-12-2019 04:006475
C14-12-2019 04:004964
C15-12-2019 04:001849
C16-12-2019 04:008218
D08-12-2019 04:002782
D09-12-2019 04:0064 
D10-12-2019 04:007364
D11-12-2019 04:003573
D12-12-2019 04:004835
D13-12-2019 04:006448
D14-12-2019 04:003264

 

Thanks,

Yogesh

1 ACCEPTED SOLUTION
mahoneypat
Employee
Employee

This expression works in a calculated column to get your desired result.  Replace "Data" throughout with your actual table name.

 

Previous Value =
VAR thisdatetime = Data[DATES]
VAR prevdatetime =
    CALCULATE (
        MAX ( Data[DATES] ),
        ALLEXCEPT ( Data, Data[name] ),
        Data[DATES] < thisdatetime
    )
RETURN
    CALCULATE (
        MIN ( Data[VALUES] ),
        ALLEXCEPT ( Data, Data[name] ),
        Data[DATES] = prevdatetime
    )

 

If this works for you, please mark it as the solution.  Kudos are appreciated too.  Please let me know if not.

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

1 REPLY 1
mahoneypat
Employee
Employee

This expression works in a calculated column to get your desired result.  Replace "Data" throughout with your actual table name.

 

Previous Value =
VAR thisdatetime = Data[DATES]
VAR prevdatetime =
    CALCULATE (
        MAX ( Data[DATES] ),
        ALLEXCEPT ( Data, Data[name] ),
        Data[DATES] < thisdatetime
    )
RETURN
    CALCULATE (
        MIN ( Data[VALUES] ),
        ALLEXCEPT ( Data, Data[name] ),
        Data[DATES] = prevdatetime
    )

 

If this works for you, please mark it as the solution.  Kudos are appreciated too.  Please let me know if not.

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors