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

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
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.