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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

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
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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