Power Query : Transpose Value Into 4 Department

muhammad susanto

Well-known Member
Joined
Jan 8, 2013
Messages
2,077
Office Version
  1. 365
  2. 2021
Platform
  1. Windows
hi all..
the following table layout , that i want to transpose into 4 department with 0/blank value based on criteria in col a (department)
split column.xlsx
ABCDEFGH
1original dataafter using power query/power bi
2DepartmentAll Budgetcol1col2col3col4
3Asset10Asset10000
4Asset2Asset2000
5Asset5Asset5000
6Asset0Asset0000
7Asset11Asset11000
8Asset12Asset12000
9Maintenance2Maintenance0200
10Maintenance3Maintenance0300
11Maintenance4Maintenance0400
12Maintenance11Maintenance01100
13Maintenance12Maintenance01200
14Maintenance23Maintenance02300
15Maintenance12Maintenance01200
16Maintenance10Maintenance01000
17Sales55Sales00550
18Sales5Sales0050
19Sales12Sales00120
20Sales11Sales00110
21Sales10Sales00100
22Marketting3Marketting0003
23Marketting4Marketting0004
24Marketting12Marketting00012
25Marketting3Marketting0003
26Marketting45Marketting00045
27Marketting11Marketting00011
28Marketting2Marketting0002
29Marketting45Marketting00045
Sheet2

my desired result in start from col1, col2,col3, col4 down
how to solve this problem
i hope one of you, give me figure out.

susant
 

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.
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    ld = List.Distinct(Source[Department]),
    lst = List.Zip({ld, {1..List.Count(ld)}}),
    tbl = List.Accumulate(lst, Source, (s,c)=> Table.AddColumn(s, "col" & Text.From(c{1}), each if [Department] = c{0} then [All Budget] else 0)),
    Result = Table.RemoveColumns(tbl, {"All Budget"})
in
    Result

Book1
ABCDEFGHI
1DepartmentAll BudgetDepartmentcol1col2col3col4
2Asset10Asset10000
3Asset2Asset2000
4Asset5Asset5000
5Asset0Asset0000
6Asset11Asset11000
7Asset12Asset12000
8Maintenance2Maintenance0200
9Maintenance3Maintenance0300
10Maintenance4Maintenance0400
11Maintenance11Maintenance01100
12Maintenance12Maintenance01200
13Maintenance23Maintenance02300
14Maintenance12Maintenance01200
15Maintenance10Maintenance01000
16Sales55Sales00550
17Sales5Sales0050
18Sales12Sales00120
19Sales11Sales00110
20Sales10Sales00100
21Marketting3Marketting0003
22Marketting4Marketting0004
23Marketting12Marketting00012
24Marketting3Marketting0003
25Marketting45Marketting00045
26Marketting11Marketting00011
27Marketting2Marketting0002
28Marketting45Marketting00045
29
Sheet1
 
Upvote 0
Solution
hi JGordon11...
why error for this show message
Expression.Error: The column 'Department' of the table wasn't found.
Details:
Department

Power Query:
let
    Source = Excel.Workbook(Web.Contents("https://docs.google.com/spreadsheets/d/e/2PACX-1vSfR-Hr0YY18Bj-3kCEd78pp5DNEbwChno4hQNbELutjLxly0W6bMFq2kR6qfBYT-I8b3d8Fd0V2RT_/pub?output=xlsx"), null, true),
    pnbp_all_Sheet = Source{[Item="pnbp_all",Kind="Sheet"]}[Data],
    ld = List.Distinct(Source[Department]),
    lst = List.Zip({ld, {1..List.Count(ld)}}),
    tbl = List.Accumulate(lst, Source, (s,c)=> Table.AddColumn(s, "col" & Text.From(c{1}), each if [Department] = c{0} then [All Budget] else 0)),
    Result = Table.RemoveColumns(tbl, {"All Budget"})
in
    Result

how fix this problem?
 
Upvote 0
SInce I can't see your data, I'm not sure - maybe reference pnbp_all_Sheet instead of Source in the ld and tbl steps
 
Upvote 0

Forum statistics

Threads
1,215,360
Messages
6,124,491
Members
449,166
Latest member
hokjock

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