August 17, 2019
Hi,
I have a question concerning the transformation of data into a table. I believe the solution is easy, but somehow I cannot get the clue. Having a sequence of headers in column1 with its value in column2. What I want to get is to transform Column1 into row headers and their records in rows below.
Input:
Column1 Column2
A 1
B 2
C 3
A 5
B 6
C 8
Desired output:
A B C
1 2 3
5 3 8
Thanks, Pavel
Power Query
Power Pivot
Xtreme Pivot Tables
Excel for Decision Making
Excel for Finance
Excel Analysis Toolpak
Power BI
Excel
Word
Outlook
Excel Expert
Excel Customer Service
PowerPoint
November 8, 2013
Hi Pavel,
Try the attached file. The query looks like this:
let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Renamed Columns" = Table.RenameColumns(Source,{{"Column1", "ID"},{"Column2","Value"}}),
#"Changed Type" = Table.TransformColumnTypes(#"Renamed Columns",{{"ID", type text}, {"Value", type text}}),
#"Grouped Rows" = Table.Group(#"Changed Type", {"ID"}, {{"Count", each _, type table [ Value=number]}}),
#"Extracted First Characters" = Table.TransformColumns(#"Grouped Rows", {{"Count", each Table.Transpose(Table.SelectColumns(_,{"Value"})) }}),
#"Expanded Count1" = Table.ExpandTableColumn(#"Extracted First Characters", "Count", Table.ColumnNames(Table.Combine(#"Extracted First Characters"[Count])), Table.ColumnNames(Table.Combine(#"Extracted First Characters"[Count]))),
#"Transposed Table1" = Table.Transpose(#"Expanded Count1"),
#"Promoted Headers1" = Table.PromoteHeaders(#"Transposed Table1", [PromoteAllScalars=true])
in
#"Promoted Headers1"
Power Query
Power Pivot
Xtreme Pivot Tables
Excel for Decision Making
Excel for Finance
Excel Analysis Toolpak
Power BI
Excel
Word
Outlook
Excel Expert
Excel Customer Service
PowerPoint
November 8, 2013
If you move up one step, you will see that the grouping step created tables in the second column. You will notice that those tables from the second column has both columns from the original table, and we need just the second column. That's what that step does:
Table.SelectColumns(_,{"Value"})
I transposed the result so we can have the values in a horizontal table that can be expanded to the right, otherwise it will expand in rows, not in columns.
I confess I was lazy, you got me... I used one of the buttons from interface to extract first char, that's how the step #"Extracted First Characters" was originally created ( had something like each Text.First(_,1) , but i replaced it with each Table.Transpose(Table.SelectColumns(_,{"Value"})) )
February 20, 2019
Catalin,
Really appreciated your patience. But I still stuck with this step: Extracted First Characters". I don't see adding a custom column with a formula nor do I see you use a custom button such as "Extract" because "Extract" was grayed out when I select "Table" column. I can't tell how you did it with this step from Power Query Editor.
Thanks!
Power Query
Power Pivot
Xtreme Pivot Tables
Excel for Decision Making
Excel for Finance
Excel Analysis Toolpak
Power BI
Excel
Word
Outlook
Excel Expert
Excel Customer Service
PowerPoint
November 8, 2013
February 20, 2019
Catalin,
Know why you used the button to extract the first character and then change the formula. Is the following an M language?
#"Extracted First Characters" = Table.TransformColumns(#"Grouped Rows", {{"Count", each Table.Transpose(Table.SelectColumns(_,{"Value"})) }}),
Thanks!
Power Query
Power Pivot
Xtreme Pivot Tables
Excel for Decision Making
Excel for Finance
Excel Analysis Toolpak
Power BI
Excel
Word
Outlook
Excel Expert
Excel Customer Service
PowerPoint
November 8, 2013
Hi Jim,
Everything in Power Query is in M language, not sure what your question is about. The only difference is that some of the operations are exposed to the user interface (you just have to use the buttons) , for everything else not included in interface you have to design your own way to process data (write custom M code to perform custom operations).
1 Guest(s)