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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
Anonymous
Not applicable

DAX formula to calculate change from yesterday

I have a data set which shows available units by product and day. I would like to add a column which calculates the change in available units for each product from the previous day. What formula would I used to create this column?

1 ACCEPTED SOLUTION

You can do it like this:

 

Capture.PNG

 

Difference With Yesterday =
SUMX (
    SUMMARIZE ( Data, Data[SKU], Data[Day] ),
    VAR ThisDay = Data[Day]
    VAR YestAmount =
        CALCULATE ( SUM ( Data[Available Count] ), Data[Day] = ThisDay - 1 )
    RETURN
        IF (
            ISBLANK ( YestAmount ),
            BLANK (),
            YestAmount - CALCULATE ( SUM ( Data[Available Count] ) )
        )
)

 

You cannot use the time intelligence PREVIOUSDAY function because you do not have a Date table

 


 


Did I answer your question correctly? Mark my answer as a solution!


Proud to be a Datanaut!  

View solution in original post

6 REPLIES 6
Anonymous
Not applicable

Do you have seperate record for each item for each day? could you please post sample data ( in copy- pastable format) with expected output?

 

Thanks
Raj

Anonymous
Not applicable

Day              SKU        Available count      Daily Change
9/15/2018   111111    20
9/15/2018   111112    17
9/15/2018   111113    14
9/16/2018   111111    18                          2
9/16/2018   111112    16                          1
9/16/2018   111113    14                          0
9/17/2018   111111    13                          5
9/17/2018   111112    13                          3
9/17/2018   111113    12                          2

 

The last column is what I am trying to create.

You can do it like this if you want to add a calculated column, even though a measure would be better

 

 

Column =
VAR PrevVal =
    CALCULATE (
        SUM ( Data[Available Count] ),
        ALLEXCEPT (
            Data,
            Data[SKU]
        ),
        Data[Day] = EARLIER ( Data[Day] ) - 1
    )
RETURN
    IF (
        ISBLANK ( PrevVal ),
        BLANK (),
        PrevVal - Data[Available Count]
    )

 


 


Did I answer your question correctly? Mark my answer as a solution!


Proud to be a Datanaut!  

Anonymous
Not applicable

What would be the measure formula?

You can do it like this:

 

Capture.PNG

 

Difference With Yesterday =
SUMX (
    SUMMARIZE ( Data, Data[SKU], Data[Day] ),
    VAR ThisDay = Data[Day]
    VAR YestAmount =
        CALCULATE ( SUM ( Data[Available Count] ), Data[Day] = ThisDay - 1 )
    RETURN
        IF (
            ISBLANK ( YestAmount ),
            BLANK (),
            YestAmount - CALCULATE ( SUM ( Data[Available Count] ) )
        )
)

 

You cannot use the time intelligence PREVIOUSDAY function because you do not have a Date table

 


 


Did I answer your question correctly? Mark my answer as a solution!


Proud to be a Datanaut!  

LivioLanzo
Solution Sage
Solution Sage

Have a look at the PREVIOUSDAY function

 

https://msdn.microsoft.com/en-us/query-bi/dax/previousday-function-dax?f=255&MSPPError=-2147217396

 


 


Did I answer your question correctly? Mark my answer as a solution!


Proud to be a Datanaut!  

Helpful resources

Announcements
Sept PBI Carousel

Power BI Monthly Update - September 2024

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

September Hackathon Carousel

Microsoft Fabric & AI Learning Hackathon

Learn from experts, get hands-on experience, and win awesome prizes.

Sept NL Carousel

Fabric Community Update - September 2024

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