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

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

Reply
barthand16
Frequent Visitor

Need Help with running total. Getting incorrect sum within the subtotal.

I have the following formula which works great within the matrix. 

Running =
VAR StartingOnhand = CALCULATE(Demand[Sum Onhand], ALL('calendar'[Period]))
RETURN
    IF (
        ISFILTERED ( 'calendar'[Period] ),
        CALCULATE (
            SUM ( 'Demand'[Inventory Table] ),
            FILTER (
                ALLSELECTED ( 'calendar'[Period] ),
                ISONORAFTER ( 'calendar'[Period], MAX ( 'calendar'[Period] ), DESC )
            )
        ) + StartingOnhand,
        StartingOnhand
    )

barthand16_0-1684253981114.png

 

However as you can tell the subtotal in my matrix is not calualting correctly. For example "period" 2320" should equal 956 (149+807)

Please let me know if you have any questions. 
 
**Note that the two rows "Material" are filtered from a total of 400 rows.**
 
5 REPLIES 5
amitchandak
Super User
Super User

@barthand16 , You need measures like , I have both addition and subtraction and Intial Inventory is a measure

 

Inventory / OnHand
[Intial Inventory] + CALCULATE(SUM(Table[Ordered]),filter(date,date[date] <=maxx(date,date[date]))) - CALCULATE(SUM(Table[Sold]),filter(date,date[date] <=maxx(date,date[date])))

Inventory / OnHand
CALCULATE(firstnonblankvalue('Date'[Month]),sum(Table[Intial Inventory]),all('Date')) + CALCULATE(SUM(Table[Ordered]),filter(date,date[date] <=maxx(date,date[date]))) - CALCULATE(SUM(Table[Sold]),filter(date,date[date] <=maxx(date,date[date])))

 

Power BI Inventory On Hand: https://youtu.be/nKbJ9Cpb-Aw

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

barthand16_0-1684354409483.png

As can be seen using the first fomula I get blanks. As well the total is not correct. For instance 2320 should equal 256 not 113. My orginal fomula worked great I just need something that will sum it correct. Also the second formula I kept getting a error that real firstnonblank value needs 2 items. 

 
Formula used for the above picture
 
Measure 2 = [Sum Onhand]+CALCULATE(SUM(Demand[Demand]),filter('calendar','calendar'[Period]<=MAXX('calendar','calendar'[Period])))+CALCULATE(SUM(Demand[Confirmed Qty]),FILTER('calendar','calendar'[Period]<=MAXX('calendar','calendar'[Period])))
 

Hi,

Share the download link of the PBI file.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

This has confidential information in the workbook. I cannot share. I beleive the issue is dependent on the rows that are in the Viz. Anything else I can provide? 

Hi,

If you can, please share a redacted version of the PBI file.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Helpful resources

Announcements
October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 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.

Top Kudoed Authors