cancel
Showing results for
Did you mean:
Highlighted
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.

 Product Stock Dispatch Total Reality A 1000 -800 200 200 B 0 -100 -100 0 C 200 -100 100 100 D 200 -300 -100 0 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?

2 REPLIES 2
Super User

## Re: Calculate sum on higher level - unexpected result

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

### I have book! Learn Power BI from Packt

Proud to be a Datanaut!

Frequent Visitor

## Re: Calculate sum on higher level - unexpected result

Hi Greg,

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:

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

Thx

Announcements

#### Challenge: Can You Solve These?

Find out how to participate in the first Power BI 'Can You Solve These?' challenge.

#### Community News & Announcements

Get your latest community news and announcements.

#### Microsoft Business Applications October Virtual Launch Event

Join us for an in-depth look at the new innovations across Dynamics 365 and the Microsoft Power Platform.

#### Win Power BI Swag with Community Kudopalooza!

Each week, complete activities and be qualified in the drawing for cool Power BI Swag.

Top Kudoed Authors
Users Online
Currently online: 150 members 1,862 guests
Recent signins: