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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
K-LED
Helper I
Helper I

Day to day difference in cumulative values

Hi All,

KLED_0-1647958983122.png

I have an example of data above. Every day, the value of each custer increase.

What I need to calculate is the day to day difference between value of each customer ? and then the percentage of the increasing value ?

 

Thanks for your help:)

 

 

7 REPLIES 7
v-shex-msft
Community Support
Community Support

HI @K-LED,

You can use the following measure formula to get the day of day difference and group by current customer:

formual =
VAR currDate =
    MAX ( Table[Date] )
VAR currAmount =
    SUM ( Table[Value] )
VAR prevDate =
    CALCULATE (
        MAX ( Table[Date] ),
        FILTER ( ALLSELECTED ( Table ), [Date] < currDate ),
        VALUES ( Table[Customer] )
    )
VAR prevAmount =
    CALCULATE (
        SUM ( Table[Value] ),
        FILTER ( ALLSELECTED ( Table ), [Date] = prevDate ),
        VALUES ( Table[Customer] )
    )
RETURN
    IF ( prevDate <> BLANK (), DIVIDE ( currAmount - prevAmount, prevAmount ), 1 )

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

@v-shex-msft Many thanks for your feedback 👍 and sorry for the delay 🙂

K-LED
Helper I
Helper I

@johnt75 thanks for your feedback😀

Sometimes I have holes in the data and I skip few days.
For example, if the current day is 03.23.2022 and the previous day is 03.20.2022, what should I do in this case to have the difference ?

With the function PREVIOUSDAY() it doesn't work.

Thanks for your help.

You can use TOPN in that case, like

Prev Value =
var currentCustomer = 'Table'[Customer]
var currentDate = 'Date'[Date]
return SELECTCOLUMNS( TOPN( 1, FILTER( 'Table', 'Table'[Customer] = currentCustomer &&
'Table'[Date] < currentDate), 'Table'[Date], DESC), "@value", 'Table'[Value] )

Thanks for the feedback.

With the TOPN function I have the next error message: 

A table of multiple values was supplied where a single value was expected.

 

That would seem to indicate that you have multiple entries for some customers on the same date. If you have a unique ID on each row you can use that as a 2nd sort column in the TOPN to make sure that you only have 1 row returned. If you don't have a unique column you could add an index column using Power Query and use that.

johnt75
Super User
Super User

How you get the Value for the previous day depends on whether Value is a column or a measure. If its a column then you can use LOOKUPVALUE, like

Prev Value =
var currentCustomer = 'Table'[Customer]
var currentDate = 'Date'[Date]
return LOOKUPVALUE( 'Table'[Value], 'Table'[Customer], currentCustomer, 'Table'[Date], 
currentDate - 1 )

and if it is a measure you can get it like

Prev Value = CALCULATE([Value], PREVIOUSDAY('Date'[Date]))

Use the appropriate method to store the previous value in a variable and then you can work out the difference and % difference

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

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

MayPowerBICarousel

Power BI Monthly Update - May 2024

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

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.