Forum Discussion
Calculating Cumulative Inventory with a Conditional "Reset to Zero" if Previous Month is Negative
- 7 months ago
Hello MuradMusleh_YE,
A standard running total in DAX will carry negative balances forward because it simply accumulates prior periods. That behavior is correct for accounting scenarios, but your requirement is a planning rule where:
The month can display a negative balance
The next month must start from 0 if the previous balance was negative
Conceptually, this becomes a sequential calculation:
VisibleBalance(n) = Carryover(n-1) + Movement(n) Carryover(n) = MAX(0, VisibleBalance(n))Because each month depends on the previous month’s computed result, this is a state-based calculation rather than a simple cumulative aggregation.
While it is possible to simulate this in DAX using complex iterator patterns (for example, SUMX with an indexed month column), those solutions can become difficult to maintain and may not scale well.
Recommended approach
For a clean and robust implementation:
Perform the month-by-month reset logic in Power Query (M), SQL, or a Dataflow
Materialize the projected balance as a column
Use DAX only for aggregation and reporting
This guarantees:
Negative months remain visible
The following month resets to 0
No circular dependency
Stable performance at scale
Hi MuradMusleh_YE,
Thank you for reaching out to Microsoft Fabric Community.
Thank you Olufemi7 for the prompt response.
As we haven’t heard back from you, we wanted to kindly follow up to check if the solution provided by the user for the issue worked? or let us know if you need any further assistance.
Thanks and regards,
Anjan Kumar Chippa
Hi @MuradMusleh_YE,
We wanted to kindly follow up to check if the solution provided by the user for the issue worked? or let us know if you need any further assistance.
Thanks and regards,
Anjan Kumar Chippa