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

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
dannvar
Frequent Visitor

Cumulative total that starts over when the total is negative

I am looking for a way to get the cumulative total to show 0 when it is a negative number and then start cumulating again when the numbers are positive. The following is what I need it to do in the table. It needs to add prior period balance + ON PO + Demand to calculate On Hand (projected) but if the On Hand projected is a -ve number it needs to show 0 and then start accumulating from when the total is +ve. I am trying to create the blue highlighted column below:

 

dannvar_0-1614821138415.png

 

1 ACCEPTED SOLUTION
rfigtree
Resolver III
Resolver III

I think this works, maybe, fingers crossed.

 

All calculated columns - have broken into steps to see what is going on.

 

net = 
var AccumPO=CALCULATE(SUM(Table1[PO]),
                FILTER(ALL(Table1),Table1[period]<=EARLIER(Table1[period])))
var AccumDemand=CALCULATE(SUM(Table1[Demand]),
                FILTER(ALL(Table1),Table1[period]<=EARLIER(Table1[period])))
return AccumPO-AccumDemand+0
offset = CALCULATE(Min(Table1[net]),
         FILTER(ALL(Table1),Table1[period]<=EARLIER(Table1[period])))
SOH(projected) =Table1[net]-[offset]

rfigtree_0-1614846426785.png

 

View solution in original post

2 REPLIES 2
rfigtree
Resolver III
Resolver III

I think this works, maybe, fingers crossed.

 

All calculated columns - have broken into steps to see what is going on.

 

net = 
var AccumPO=CALCULATE(SUM(Table1[PO]),
                FILTER(ALL(Table1),Table1[period]<=EARLIER(Table1[period])))
var AccumDemand=CALCULATE(SUM(Table1[Demand]),
                FILTER(ALL(Table1),Table1[period]<=EARLIER(Table1[period])))
return AccumPO-AccumDemand+0
offset = CALCULATE(Min(Table1[net]),
         FILTER(ALL(Table1),Table1[period]<=EARLIER(Table1[period])))
SOH(projected) =Table1[net]-[offset]

rfigtree_0-1614846426785.png

 

Thank you this will work. I just need to apply this as a measure since I need to replicate it for multiple products. Thank you so much for your help! @rfigtree

Helpful resources

Announcements
March Fabric Community Update

Fabric Community Update - March 2024

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

Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.

Top Solution Authors