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
brian_c999
New Member

Need help with Power Query

Hi,

 

Apologies for multiple posts as my previous one was tagged as spammed and I could not reply.

 

Is there anyway to transform the sample data into the second table below. Basically, some employees need to split based on a ratio to other cost centres (B, C, D or E). Using Staff B as an example, his costs should be split across cost centres C & D while no costs should remain at cost centre B.

Account CodeAccount NameAmountCost CentreNamesBCDE
446Salary1000AStaff A    
447Annual Leave100AStaff A    
449Superannuation100AStaff A    
446Salary2000BStaff B 10001000 
447Annual Leave200BStaff B 100100 
449Superannuation100BStaff B 5050 
446Salary2500CStaff C  2000500
447Annual Leave100CStaff C  8020
449Superannuation100CStaff C  8020

 

Desired Output:

Cost CentreAccount CodeAccount NameNet
A446Salary1000
A447Annual Leave100
A449Superannuation100
B446Salary0
B447Annual Leave0
B449Superannuation0
C446Salary1000
C447Annual Leave100
C449Superannuation50
D446Salary3000
D447Annual Leave180
D449Superannuation130
E446Salary500
E447Annual Leave20
E449Superannuation20

 

Thank you in advance

1 ACCEPTED SOLUTION
lbendlin
Super User
Super User

You need to modify your source table to include the destination for all rows.

 

lbendlin_0-1717523308514.png

And then you can remove all the redundant columns

lbendlin_1-1717523466184.png

 

 

Having the split in columns is generally bad practice for Power BI (common for Excel data) - maintenance red flag.

 

Anyway, here is the transform :

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjExU9JRCk7MSSyqBDIMDQwMgJQCCo7VAakzB7Id8/JKE3MUfFITy1IhqnEotgQZWlqQWpQI0lGSmZ+HVzmKG6ByUKfAXYTTFQj1SHbgcQZUvakBjMDnChA2gjjBFEgScgQIWxiA9RDhBBTVsQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Account Code" = _t, #"Account Name" = _t, A = _t, B = _t, C = _t, D = _t, E = _t]),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(Source, {"Account Code", "Account Name"}, "Cost Centre", "Net"),
    #"Changed Type" = Table.TransformColumnTypes(#"Unpivoted Other Columns",{{"Net", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Cost Centre", "Account Code", "Account Name"}, {{"Net", each List.Sum([Net]), type text}}),
    #"Sorted Rows" = Table.Sort(#"Grouped Rows",{{"Cost Centre", Order.Ascending}, {"Account Code", Order.Ascending}})
in
    #"Sorted Rows"

How to use this code: Create a new Blank Query. Click on "Advanced Editor". Replace the code in the window with the code provided here. Click "Done". Once you examined the code, replace the Source step with your own source.

 

lbendlin_2-1717523666583.png

 

 

View solution in original post

1 REPLY 1
lbendlin
Super User
Super User

You need to modify your source table to include the destination for all rows.

 

lbendlin_0-1717523308514.png

And then you can remove all the redundant columns

lbendlin_1-1717523466184.png

 

 

Having the split in columns is generally bad practice for Power BI (common for Excel data) - maintenance red flag.

 

Anyway, here is the transform :

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WMjExU9JRCk7MSSyqBDIMDQwMgJQCCo7VAakzB7Id8/JKE3MUfFITy1IhqnEotgQZWlqQWpQI0lGSmZ+HVzmKG6ByUKfAXYTTFQj1SHbgcQZUvakBjMDnChA2gjjBFEgScgQIWxiA9RDhBBTVsQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Account Code" = _t, #"Account Name" = _t, A = _t, B = _t, C = _t, D = _t, E = _t]),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(Source, {"Account Code", "Account Name"}, "Cost Centre", "Net"),
    #"Changed Type" = Table.TransformColumnTypes(#"Unpivoted Other Columns",{{"Net", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"Cost Centre", "Account Code", "Account Name"}, {{"Net", each List.Sum([Net]), type text}}),
    #"Sorted Rows" = Table.Sort(#"Grouped Rows",{{"Cost Centre", Order.Ascending}, {"Account Code", Order.Ascending}})
in
    #"Sorted Rows"

How to use this code: Create a new Blank Query. Click on "Advanced Editor". Replace the code in the window with the code provided here. Click "Done". Once you examined the code, replace the Source step with your own source.

 

lbendlin_2-1717523666583.png

 

 

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

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

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

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