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

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

Reply
TomikBlack
New Member

Add detail row as difference between details sum vs header value

Hi Experts, 

any ideas how to Add detail row as difference between details sum vs header value? I have many files xlsx files where header sum and also detail is presented, but sum <> sum(details) and for difference i d like to generate new product it can be always "c" where ll be difference from header counted for particular file. 

Thanks Tomas

sample file 1

header table
sum 
120 
  
  
detail table
productvalue
a50
b20

----------------------------------------------

sample file 2

header table 
sum 
100 
  
  
detail table 
productvalue
a70
b20

-------------------------------------------

expected output pbi, in yellow line i d like to have "c". Thinking of Table.InsertRows, but its not dynamic, so iam out of ideas.

TomikBlack_0-1679157982842.png

1 ACCEPTED SOLUTION
PiEye
Resolver II
Resolver II

Hi @TomikBlack 

 

I'm assuming you have two tables in power query that look like this:

PiEye_0-1679165140506.pngPiEye_1-1679165160122.png

 

 

I was able to create rows for "c" by converting the detail values to negative, appending the header, and grouping and summing to get a difference, and appending the details back onto it.

 

Here are the steps:

New query created by referencing details & adding a new column which is the negative of the values:

PiEye_2-1679165402710.pngPiEye_3-1679165439199.png

 

Header rows added on. We can then group, and "sum" to get the difference. 

PiEye_4-1679165487905.pngPiEye_5-1679165501389.png

 

These grouped values are our "c"

PiEye_6-1679165547608.png

 

We can then append the details back on

PiEye_7-1679165809117.png

 

I can then create a matrix in the UI with this additional line:

PiEye_8-1679165892283.png

 

 

 

HTH -Full M Query for this table below

Pi

Please: Don't forget to mark as an answer if this helped!

 

let
Source = Detail,
#"Removed Columns" = Table.RemoveColumns(Source,{"product"}),
#"Added Custom" = Table.AddColumn(#"Removed Columns", "sum", each -[value]),
#"Appended Query" = Table.Combine({#"Added Custom", Header}),
#"Grouped Rows" = Table.Group(#"Appended Query", {"Source.Name"}, {{"value", each List.Sum([sum]), type number}}),
#"Added Custom1" = Table.AddColumn(#"Grouped Rows", "product", each "c"),
#"Appended Query1" = Table.Combine({#"Added Custom1", Detail}),
#"Reordered Columns" = Table.ReorderColumns(#"Appended Query1",{"Source.Name", "product", "value"})
in
#"Reordered Columns"

 

 

View solution in original post

1 REPLY 1
PiEye
Resolver II
Resolver II

Hi @TomikBlack 

 

I'm assuming you have two tables in power query that look like this:

PiEye_0-1679165140506.pngPiEye_1-1679165160122.png

 

 

I was able to create rows for "c" by converting the detail values to negative, appending the header, and grouping and summing to get a difference, and appending the details back onto it.

 

Here are the steps:

New query created by referencing details & adding a new column which is the negative of the values:

PiEye_2-1679165402710.pngPiEye_3-1679165439199.png

 

Header rows added on. We can then group, and "sum" to get the difference. 

PiEye_4-1679165487905.pngPiEye_5-1679165501389.png

 

These grouped values are our "c"

PiEye_6-1679165547608.png

 

We can then append the details back on

PiEye_7-1679165809117.png

 

I can then create a matrix in the UI with this additional line:

PiEye_8-1679165892283.png

 

 

 

HTH -Full M Query for this table below

Pi

Please: Don't forget to mark as an answer if this helped!

 

let
Source = Detail,
#"Removed Columns" = Table.RemoveColumns(Source,{"product"}),
#"Added Custom" = Table.AddColumn(#"Removed Columns", "sum", each -[value]),
#"Appended Query" = Table.Combine({#"Added Custom", Header}),
#"Grouped Rows" = Table.Group(#"Appended Query", {"Source.Name"}, {{"value", each List.Sum([sum]), type number}}),
#"Added Custom1" = Table.AddColumn(#"Grouped Rows", "product", each "c"),
#"Appended Query1" = Table.Combine({#"Added Custom1", Detail}),
#"Reordered Columns" = Table.ReorderColumns(#"Appended Query1",{"Source.Name", "product", "value"})
in
#"Reordered Columns"

 

 

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Kudoed Authors