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
sumitnegi1266
Frequent Visitor

How to cumulative sum with condition

Hi,

I have below data and need to now calculate the cumulative sum of forecast value at a certain date. I have a days measure which I am adding with the date e.g. 16th Aug + 4 days = 20th Aug. I then need to calculate Cumulative sum for 20th Aug, which should be 160. How to calculate it using dax?

sumitnegi1266_0-1692195833189.png

 

Appreciate any help here!

1 ACCEPTED SOLUTION
kameronyork
Resolver I
Resolver I

This can be accomplished either in a measure to be used in a table,  or in a calculated column in PowerBI's Data View.  The measure, when applied to a table - with the Date column added -  will result in this:
2.png
The column added in the Data View will result in this:
1.png

 

Here is the code I used:
Measure

Cumulative Sum = 
VAR current_date = SELECTEDVALUE('Table'[Date])
RETURN

CALCULATE( SUM('Table'[Forecast Value]), 'Table'[Date] <= current_date)
// Returns the sum for all dates less than or equal to the date on the current row.

Column

Running total = 
VAR current_date = 'Table'[Date]
RETURN

CALCULATE( SUM('Table'[Forecast Value]), ALL('Table'), 'Table'[Date] <= current_date)
// Returns the sum for all dates less than or equal to the date on the current row.

 

Also, If you wanted it to count up differently based on certain criteria - like when it becomes a new year - I would suggest using the column method and doing something like the following:
3.png

 

I hope this helps!  If it does, please mark this as the solution.  Kudos are appreciated 🙂

View solution in original post

5 REPLIES 5
sumitnegi1266
Frequent Visitor

@kameronyork Thanks for you response. The date I am using is a calculated date which is a measure. I tried using below but got an error i.e. "Visual has exceeded the available resources"

 
Cumulative Calc =
var _date = [Date to hold]
return
CALCULATE( SUM('Forecast Sales'[Forecast Value]), 'Forecast Sales'[Date] <= _date)
 
sumitnegi1266_0-1692198478523.png

 

Would you be willing to provide the measure you are using for the date?  I will then do some testing to find the best solution! 🙂

@kameronyork Below is the date measure I am using. Max('Lead Times'[LeadTime]) is the number of days I am using from another table which has a relationship with current table

 

sumitnegi1266_0-1692199423346.png

 

Would you please post more information about this lead times table?  Why does the date need to be pulled from it?  This will hlep me understand the question better 🙂

kameronyork
Resolver I
Resolver I

This can be accomplished either in a measure to be used in a table,  or in a calculated column in PowerBI's Data View.  The measure, when applied to a table - with the Date column added -  will result in this:
2.png
The column added in the Data View will result in this:
1.png

 

Here is the code I used:
Measure

Cumulative Sum = 
VAR current_date = SELECTEDVALUE('Table'[Date])
RETURN

CALCULATE( SUM('Table'[Forecast Value]), 'Table'[Date] <= current_date)
// Returns the sum for all dates less than or equal to the date on the current row.

Column

Running total = 
VAR current_date = 'Table'[Date]
RETURN

CALCULATE( SUM('Table'[Forecast Value]), ALL('Table'), 'Table'[Date] <= current_date)
// Returns the sum for all dates less than or equal to the date on the current row.

 

Also, If you wanted it to count up differently based on certain criteria - like when it becomes a new year - I would suggest using the column method and doing something like the following:
3.png

 

I hope this helps!  If it does, please mark this as the solution.  Kudos are appreciated 🙂

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.