Book1 | |||||||
---|---|---|---|---|---|---|---|
A | B | C | D | E | |||
2 | order number | item | |||||
3 | 1 | a | |||||
4 | 1 | a | |||||
5 | 1 | a | |||||
6 | 2 | b | |||||
7 | 2 | b | |||||
8 | 2 | c | |||||
9 | 2 | d | |||||
10 | |||||||
11 | result | ||||||
12 | Order number | ||||||
13 | 1 | a | a | a | |||
14 | 2 | b | b | c | d | ||
Sheet1 |
Book1 | |||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
H | I | J | K | L | M | N | O | P | Q | R | S | T | |||
1 | Column1 | Column2 | Column3 | Column4 | Column5 | Column6 | Column7 | Column8 | Column9 | Column10 | Column11 | Column12 | Column13 | ||
2 | order number | 1 | 1 | 1 | 2 | 2 | 2 | 2 | result | Order number | 1 | 2 | |||
3 | item | a | a | a | b | b | c | d | a | b | |||||
4 | a | b | |||||||||||||
5 | a | c | |||||||||||||
6 | d | ||||||||||||||
Sheet2 |
could you please explain to me in detail? i am new to this power queryThe sample suggests the order number is sorted.
If that is the case, one can use a group by, with the options groupkind.local. That's a fast grouping.
As aggregation using all rows, named Sub or something Aline. Add a custom column with the formula table.selectcolumns(,"Item"). Wrap it in table.transpose. Expand the table.
Book1 | ||||
---|---|---|---|---|
A | B | |||
1 | order number | item | ||
2 | 1 | a | ||
3 | 1 | a | ||
4 | 1 | a | ||
5 | 2 | b | ||
6 | 2 | b | ||
7 | 2 | c | ||
8 | 2 | d | ||
Sheet1 |
let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Grouped Rows" = Table.Group(Source, {"order number"}, {{"All Rows", each _, type table [order number=text, item=text]}}),
#"Added Custom" = Table.AddColumn(#"Grouped Rows", "Custom", each Table.RemoveColumns([All Rows],"order number")),
#"Added Custom1" = Table.AddColumn(#"Added Custom", "Custom.1", each Table.Transpose( [Custom] )),
#"Expanded Custom.1" = Table.ExpandTableColumn(#"Added Custom1", "Custom.1", {"Column1", "Column2", "Column3", "Column4"}, {"Column1", "Column2", "Column3", "Column4"}),
#"Removed Columns" = Table.RemoveColumns(#"Expanded Custom.1",{"All Rows", "Custom"})
in
#"Removed Columns"
Book1 | |||||||
---|---|---|---|---|---|---|---|
D | E | F | G | H | |||
1 | order number | Column1 | Column2 | Column3 | Column4 | ||
2 | 1 | a | a | a | |||
3 | 2 | b | b | c | d | ||
Sheet1 |
let
Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"order number", Int64.Type}, {"item", type text}}),
#"Grouped Rows" = Table.Group(#"Changed Type", {"order number"}, {{"Items", each List.Count(List.Distinct([item]))=1, type nullable logical}}, GroupKind.Local)
in
#"Grouped Rows"