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

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Powerananya
New Member

DAX Help: Cumulative Sum with Reset on Large Negative Values in Power BI.

I am working on a Power BI report and need help creating a DAX expression for a calculated column. My goal is to calculate a cumulative sum of sales values, but I want the sum to reset to zero whenever a large negative value causes the cumulative total to drop below zero. For example, if the cumulative sum is 92 and a subsequent value of -135 is encountered, the result should reset to zero instead of going negative

1 ACCEPTED SOLUTION
bhanu_gautam
Super User
Super User

@Powerananya , 

Sort your data: Ensure your data is sorted by the date or the order in which you want to calculate the cumulative sum.

Create the calculated column:This expression will calculate the cumulative sum and reset it to zero whenever the cumulative total drops below zero.

DAX
CumulativeSales =
VAR CurrentRow = EARLIER('Sales'[RowID])
VAR CurrentValue = 'Sales'[SalesValue]
VAR PreviousCumulative =
CALCULATE(
SUM('Sales'[SalesValue]),
FILTER(
'Sales',
'Sales'[RowID] < CurrentRow
)
)
VAR NewCumulative = PreviousCumulative + CurrentValue
RETURN
IF(NewCumulative < 0, 0, NewCumulative)




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






View solution in original post

1 REPLY 1
bhanu_gautam
Super User
Super User

@Powerananya , 

Sort your data: Ensure your data is sorted by the date or the order in which you want to calculate the cumulative sum.

Create the calculated column:This expression will calculate the cumulative sum and reset it to zero whenever the cumulative total drops below zero.

DAX
CumulativeSales =
VAR CurrentRow = EARLIER('Sales'[RowID])
VAR CurrentValue = 'Sales'[SalesValue]
VAR PreviousCumulative =
CALCULATE(
SUM('Sales'[SalesValue]),
FILTER(
'Sales',
'Sales'[RowID] < CurrentRow
)
)
VAR NewCumulative = PreviousCumulative + CurrentValue
RETURN
IF(NewCumulative < 0, 0, NewCumulative)




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.