Power Query - Split an amount into multiple rows

jon999

New Member
Joined
Aug 24, 2015
Messages
37
Hi

I have a scenario where I need to be able to split the amount over multiple rows. Example of current data

Invoice numberLocationQuantityAmount
100A210
101A430
101B10

<tbody>
</tbody>

What I need to do is against invoice 101 be able to split the total invoice amount being 30 over the rows for invoice 101 based on quantity. The calculation needs to be:

Location A 4/5 * 30 = 24
Location B 1/5 * 30 =6

So it needs to look like this

Invoice numberLocationQuantityAmount
100A210
101A424
101B16

<tbody>
</tbody>


Thanks
 

Excel Facts

Copy formula down without changing references
If you have =SUM(F2:F49) in F50; type Alt+' in F51 to copy =SUM(F2:F49) to F51, leaving the formula in edit mode. Change SUM to COUNT.
let

Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Invoice number", Int64.Type}, {"Location", type text}, {"Quantity", Int64.Type}, {"Amount", Int64.Type}}),
Table1 = Table.Group(#"Changed Type", {"Invoice number"}, {{"TotQty", each List.Sum([Quantity]), type number}, {"TotAmt", each List.Sum([Amount]), type number}}),

#"Changed Type1" = Table.TransformColumnTypes(Source,{{"Invoice number", Int64.Type}, {"Location", type text}, {"Quantity", Int64.Type}, {"Amount", Int64.Type}}),
#"Grouped Rows" = Table.Group(#"Changed Type1", {"Invoice number"}, {{"Count", each _, type table}}),
#"Merged Queries" = Table.NestedJoin(#"Grouped Rows",{"Invoice number"},Table1,{"Invoice number"},"Table1",JoinKind.LeftOuter),
#"Expanded Table1" = Table.ExpandTableColumn(#"Merged Queries", "Table1", {"TotQty", "TotAmt"}, {"TotQty", "TotAmt"}),
#"Expanded Count" = Table.ExpandTableColumn(#"Expanded Table1", "Count", {"Location", "Quantity", "Amount"}, {"Location", "Quantity", "Amount"}),
#"Added Custom" = Table.AddColumn(#"Expanded Count", "Amount1", each [Quantity]/[TotQty]*[TotAmt]),
#"Removed Columns" = Table.RemoveColumns(#"Added Custom",{"Amount", "TotQty", "TotAmt"})
in
#"Removed Columns"
 
Upvote 0

Forum statistics

Threads
1,214,944
Messages
6,122,391
Members
449,080
Latest member
Armadillos

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top