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

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
lpost1214
Regular Visitor

Totals not working properly - product hierarchy

CustomerProduct TypeItemValueMonth 1Month 2Grand Total      
WalmartCough DropAForecast75100175      
WalmartCough DropAOpen Orders10075175      
WalmartCough Drop ADifference02525      
WalmartCough Drop BForecast125150275      
WalmartCough Drop BOpen Orders110180290      
WalmartCough Drop BDifference152035      
   Total of Difference154560      
             
Difference formula = if( open orders > forecast, 0, forecast - open orders)        
             
CustomerProduct TypeValueMonth 1Month 2Grand Total       
WalmartCough DropForecast200250450       
WalmartCough DropOpen Orders210255465       
WalmartCough Drop Difference000       
 **Desired Result 154560       
             
When I collapse item view to just product type, the difference formula is being applied to the totals rather than just totaling the item level detail. How can I achieve this? 
2 REPLIES 2
Ashish_Mathur
Super User
Super User

Hi,

It looks like the first table is a visual (not the raw data).  Share the raw data table in a format that can be pasted in an MS Excel file and show the expected result.


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

I reformatted that data a bit. Ideally, you want a column with Date and have many rows, and also have Forecast and Open Orders as separate field. When you do this, you can make the difference field in PowerQuery (unless it is a field you are bringing in from your source, in which case - pivot it right along with open orders and forecast).

 

Here are the results - I get the 15 in month 1 and 25 in month 2 (it looks like for item A you have the difference as 20, but since open orders are greater than forecast, it should be 0):

audreygerred_0-1707433697833.png

audreygerred_2-1707433871358.png

audreygerred_3-1707434115251.pngaudreygerred_4-1707434138776.png

 

 

audreygerred_1-1707433735232.png

Here's the M-Code I used in Power Query:

let
Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45Wcs4vTc9QcCnKL1DSUXIEYrf8otTkxOISINPcFEgY6hvqGxkYmSjF6mBR7V+QmqfgX5SSWgRSamCAV4MTqvGGRvjNd8Iw3xC/+WjOhzjHiHj3g/2LWz26803xG4/pfAtUDbEA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Product Type" = _t, Item = _t, Value = _t, Column1 = _t, Date = _t]),
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Product Type", type text}, {"Item", type text}, {"Value", type text}, {"Column1", Int64.Type}}),
#"Renamed Columns" = Table.RenameColumns(#"Changed Type",{{"Column1", "Amount"}}),
#"Pivoted Column" = Table.Pivot(#"Renamed Columns", List.Distinct(#"Renamed Columns"[Value]), "Value", "Amount", List.Sum),
#"Added Custom" = Table.AddColumn(#"Pivoted Column", "Difference", each if [Open Order] > [Forecast] then 0 else [Forecast] - [Open Order]),
#"Changed Type1" = Table.TransformColumnTypes(#"Added Custom",{{"Difference", Int64.Type}})
in
#"Changed Type1"





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!





Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

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 Solution Authors
Top Kudoed Authors