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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Tido
Frequent Visitor

Calculate sum on higher level - unexpected result

Hi,

 

maybe you can help me by solving the following issue. I want calculate the total sum of some products. If the total sum for each product is lower than zero, it shall get the value zero. On product level this works properly with the formula below, but not on higher aggregated level.

 

ProductStockDispatchTotalReality
A1000-800200200
B0-100-1000
C200-100100100
D200-300-1000
   100

100

 

Instead of the red marked 100 pcs, I expect a value of 300 pcs.

 

Currently I use the following formula / measure, to calculate the value along the time:

 

CumStockQty =
VAR Reality = CALCULATE(StockData_Stock[Stock Qty] - StockData_Dispatch[Total Dispatch Qty1];
                   FILTER(all(StockData_Date); [Date] >= max(StockData_Date[Date]) - 365 && [Date] <= max(StockData_Date[Date])))

VAR z = if(Total>0;Total;0)
Return z

 

Any idea what I can adjust to get a figure of 300 pcs on the highest aggregation level?

 

Thanks for your support!!

2 REPLIES 2
Tido
Frequent Visitor

Hi Greg,

 

thx for your response. I've tried to adjust the measure according to your proposal:

 

CumStockQty_real =
VAR single = CALCULATE(StockData_MasterData[Stock Qty] + StockData_Receipt[Total Receipt Qty] + StockData_Dispatch[Total Dispatch Qty1];
             FILTER(all(StockData_Date); [Date] >= max(StockData_Date[Date]) - 365 && [Date] <= max(StockData_Date[Date])))

VAR total = SUMMARIZE(StockData_Date;StockData_Date[Date];"Qty";if(single > 0; single;0))

RETURN if(HASONEVALUE(StockData_MasterData[ItemNumber]);if(single > 0; single;0);SUMX(total;[Qty]))

 

But at the end, I get out the same result:

2018-10-24_09h50_45.png

 

Do you have an idea, what I'm doing wrong?

 

Thx

Greg_Deckler
Community Champion
Community Champion

This looks like a measure totals problem. Very common. See my post about it here: https://community.powerbi.com/t5/DAX-Commands-and-Tips/Dealing-with-Measure-Totals/td-p/63376

 

Also, see The Final Word on Measure Totals:

https://community.powerbi.com/t5/Quick-Measures-Gallery/Measure-Totals-The-Final-Word/m-p/547907



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

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