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 Measure to calculate the difference in cumulative within the same column

Hello All,

I have the following table with the Cumulative Amounts split across Dates and Type and I want to calculate the amounts in between dates.

For Example: Between 6/27 and 7/25, the amount that was shipped was 35 (721-685) for Type=PF1. Also since 5/30 is the first date in the table, the cumulative amount = Desired Measure

 

Untitled.png

 

How do I do this in DAX?

I tried using EARLIER but since the dates do not increment by 1 every time, I'm not getting the desired amount

 

 

=
VAR CumulativeAmountPreviousDate =
CALCULATE (
SUM ( 'Table'[CumulativeAmount] ),
FILTER (
ALL ( 'Table' ),
'Table'[Date]
= EARLIER ( 'Table'[Date] ) - 1
&& 'Table'[Type] = EARLIER ( 'Table'[Type] )
)
)

RETURN
'Table'[CumulativeAmount] - CumulativeAmountPreviousDate

 

 

1 ACCEPTED SOLUTION
Ashish_Mathur
Super User
Super User

Hi,

This calculated column formula works

 

=Data[Cumulative amount]-LOOKUPVALUE(Data[Cumulative amount],Data[Date],CALCULATE(MAX(Data[Date]),FILTER(Data,Data[Type]=EARLIER(Data[Type])&&Data[Date]<EARLIER(Data[Date]))),Data[Type],Data[Type])

 

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

View solution in original post

5 REPLIES 5
Ashish_Mathur
Super User
Super User

Hi,

This calculated column formula works

 

=Data[Cumulative amount]-LOOKUPVALUE(Data[Cumulative amount],Data[Date],CALCULATE(MAX(Data[Date]),FILTER(Data,Data[Type]=EARLIER(Data[Type])&&Data[Date]<EARLIER(Data[Date]))),Data[Type],Data[Type])

 

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

I tried your solution but I'm getting this error

 

Calculation error in column '[]: A table of multiple values was supplied where a single value was expected.

Well then you obviously have cases where the same Date and Type combination repeats.  Share a representative dataset and show the expetced result.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

You were absolutely right. I grouped them by data and type and your formula worked! Thanks a lot!

You are welcome.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

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.