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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
SPGMat
Regular Visitor

Calculate a Running Total as a variable which Resets based on a condition

Hi Members,

 

Im new to the world of PowerBI and I need help with the following Running Total I need to calculate in DAX.

 

Definition -> BalancePick = OpeningStockPosition + POs Pick - Demand

 

I want to calculate a Running Total on BalancePick by Date and Item (StockAfter Picks).

 

So My Current DAX Works well in the instance we have a large OpeningStockPosition and plentiful POs Pick on certain Dates:

 

StockAfter Picks =
CALCULATE (
    SUM ( 'Summarized SOF'[BalancePick] ),
    FILTER (
        ALLEXCEPT (
            'Summarized SOF',
            'Summarized SOF'[Sales Orders and Forecast_Customer Item Number]
        ),
        'Summarized SOF'[Sales Orders and Forecast_Pick Date]
            <= EARLIER ( 'Summarized SOF'[Sales Orders and Forecast_Pick Date] )
            && 'Summarized SOF'[Sales Orders and Forecast_Customer Item Number]
                <= MAX ( 'Summarized SOF'[Sales Orders and Forecast_Customer Item Number] )
    )
)

 

Item Example 37816 where DAX Works

 

SPGMat_0-1703875769211.png

 

Item Example 37916 where DAX doesnt work

 

It doesnt work as No Opening Stock Position, plus not enough POs Pick.

 

Currently:

 

SPGMat_1-1703875950347.png

 

What I actually need StockAfter Picks to show (Yellow Highlights):

 

SPGMat_3-1703876665282.png

 

So what I actually need DAX to do is compute a running total between the current row and row above and check if its negative set to zero or its fine, then use that in the next running total computation.

 

In Variable Form

 

Let Opening Stock Postion= A

Let POs Pick = B

Let Demand = C

 

StockAfter Picks Row 1 = IF( A(1)+B(1)-C(1) <0 ,0 A(1)+B(1)-C(1) ) 

 

Let StockAfter Picks Row 1 = NewStockPosition(1)

 

StockAfter Picks Row 2 = IF( NewStockPostion(1) +B(2)-C(2) <0 ,0 ,NewStockPostion(1)+B(2)-C(2) )

 

Let StockAfter Picks Row 2 = NewStockPosition(2)

 

And it iterates so on based on the date column and item number column.

2 REPLIES 2
v-yiruan-msft
Community Support
Community Support

Hi @SPGMat ,

You can refer the following thread which has the similar requirement as yours to get it:

Re: Running Balance - Reset to Zero - Microsoft Fabric Community

 

If the above one can't help you get the expected result, please provide some raw data in your table 'Summarized SOF' (exclude sensitive datawith Text format and your expected result.  It would be helpful to find out the solution. You can refer the following link to share the required info:

How to provide sample data in the Power BI Forum

 

And It is better if you can share a simplified pbix file. You can refer the following link to upload the file to the community. Thank you.

How to upload PBI in Community

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
lbendlin
Super User
Super User

running totals in DAX cannot be conditional.  The only place where you can do that is List.Accumulate in Power Query.

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

AugPowerBI_Carousel

Power BI Monthly Update - August 2024

Check out the August 2024 Power BI update to learn about new features.

August Carousel

Fabric Community Update - August 2024

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