Collapse Multiple Rows to Single Row

GreenCat223

New Member
Joined
Mar 27, 2024
Messages
5
Office Version
  1. 365
  2. 2021
  3. 2019
Platform
  1. Windows
Hi there!

I was wondering if someone could help explain why my data doesn't pivot in Power Query?

This is how it comes out of the system (Table 1):
EmpNumProductNameInputNameEntryValueElement Entry IDElement Entry ID Value
Emp1ApplesTypeGrannySmith
123​
345​
Emp1ApplesUnits
5​
123​
347​
Emp1ApplesTypeGala
456​
349​
Emp1ApplesUnits
3​
456​
351​
Emp1ApplesTypeBraeburn
789​
353​
Emp1ApplesUnits
1​
789​
355​
Emp1ApplesTypePinkLady
321​
357​
Emp1ApplesUnits
7​
321​
359​
Emp2OrangesTypeSatsuma
566​
756​
Emp2OrangesUnits
6​
566​
758​
Emp3OrangesTypeSatsuma
788​
555​
Emp3OrangesUnits
6​
788​
557​
Emp4PearsUnits
5​
458​
997​
Emp5MangoTypeChaunsa
432​
160​
Emp5MangoUnits
7​
432​
162​
Emp5MangoSeasonSummer
432​
164​
Emp6PlumTypePlum
571​
166​

This is how I want the data to look like (Table 2):

EmpNumProductNameTypeUnitsSeasonElement Entry ID
Emp1ApplesGrannySmith
5​
123​
Emp1ApplesGala
3​
456​
Emp1ApplesBraeburn
1​
789​
Emp1ApplesPinkLady
7​
321​
Emp5MangoChaunsa
7​
Summer
432​
Emp2OrangeSatsuma
6​
566​
Emp3OrangeSatsuma
6​
788​
Emp4Pears
5​
789​

What I don't understand is why this data (Table 3) is still expanded as Table 1 when I use the pivot feature in Power Query.

EmpNumProductNameTypeElement Entry ID ValueUnitsSeasonElement Entry ID
Emp1Apples
351​
3​
456​
Emp1ApplesGala
349​
456​
Emp1Apples
355​
1​
789​
Emp1ApplesBraeburn
353​
789​
Emp1Apples
347​
5​
123​
Emp1ApplesGrannySmith
345​
123​
Emp1Apples
359​
7​
321​
Emp1ApplesPinkLady
357​
321​
Emp5MangoChaunsa
160​
432​
Emp5Mango
162​
7​
432​
Emp5Mango
164​
Summer
432​
Emp3Oranges
557​
6​
788​
Emp2OrangesSatsuma
756​
566​
Emp3OrangesSatsuma
555​
788​
Emp2Oranges
758​
6​
566​
Emp4Pears
997​
5​
458​
Emp6PlumPlum
166​
571​

I'm aware that if I remove the "Element Entry ID Value" column, prior to pivoting I will get the result I want in Table 2.

An explanation in laymen's terms would be really helpful so I can understand it better!

Thank you very much for your time. 😊
 

Excel Facts

What is the last column in Excel?
Excel columns run from A to Z, AA to AZ, AAA to XFD. The last column is XFD.
Share your Mcode for the example you have provided so it can be analyzed.
 
Upvote 0
This is the M-Code for my solution:

let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"EmpNum", type text}, {"ProductName", type text}, {"InputName", type text}, {"EntryValue", type any}, {"Element Entry ID", Int64.Type}}),
#"Pivoted Column" = Table.Pivot(#"Changed Type", List.Distinct(#"Changed Type"[InputName]), "InputName", "EntryValue"),
#"Reordered Columns" = Table.ReorderColumns(#"Pivoted Column",{"EmpNum", "ProductName", "Type", "Units", "Season", "Element Entry ID"}),
#"Sorted Rows" = Table.Sort(#"Reordered Columns",{{"ProductName", Order.Ascending}})
in
#"Sorted Rows"
 
Upvote 0
Remove the Element Entry ID Value column before you unpivot. It is unique for every row, which stops the transformation from doing what you want.
 
Upvote 0
Solution

Forum statistics

Threads
1,216,500
Messages
6,131,016
Members
449,615
Latest member
Nic0la

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