I have some barcode scanner which lists out the codes on a column in Excel.
The goal is to divide the original column into a table as per the test cases below. Does anyone have an idea in how to achieve it?
Table Before:
A |
---|
XXID0081 |
45011 |
654000 |
2 |
654001 |
3 |
654002 |
4 |
XXID0082 |
45012 |
785902 |
2 |
3 |
XXID0083 |
45013 |
888981 |
2 |
888982 |
3 |
Table After:
A | B | C | D |
---|---|---|---|
XXID0081 | 45011 | 654000 | 2 |
XXID0081 | 45011 | 654001 | 3 |
XXID0081 | 45011 | 654002 | 4 |
XXID0082 | 45012 | 785902 | 5 |
XXID0083 | 45013 | 888981 | 2 |
XXID0083 | 45013 | 888982 | 3 |
I have tried using the Power query but wanted to do it with excel functions. Tried using the WRAPROWS
=WRAPROWS(A2:A300,4)
not working. There is one more problem when the qty is twice for A,B,C column it will be added up. for example as in the screenprints.
Please ask away if you have any questions. I will post the power query code if needed. TIA.
let
Source = Excel.CurrentWorkbook(){[Name="Table6"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"A", type text}}),
#"Added Conditional Column" = Table.AddColumn(#"Changed Type", "Custom", each if Text.StartsWith([A], "XXID") then [A] else null),
#"Filled Down" = Table.FillDown(#"Added Conditional Column",{"Custom"}),
#"Filtered Rows" = Table.SelectRows(#"Filled Down", each not Text.StartsWith([A], "UID")),
#"Added Custom" = Table.AddColumn(#"Filtered Rows", "Custom.1", each if Text.Length([A]) = 5 then [A] else null),
#"Filled Down1" = Table.FillDown(#"Added Custom",{"Custom.1"}),
#"Added Custom1" = Table.AddColumn(#"Filled Down1", "Custom.2", each if Text.Length([A]) = 6 then [A] else null),
#"Filled Down2" = Table.FillDown(#"Added Custom1",{"Custom.2"}),
#"Filled Up" = Table.FillUp(#"Filled Down2",{"Custom.2"}),
#"Added Custom2" = Table.AddColumn(#"Filled Up", "Custom.3", each if Text.Length([A]) < 4 then [A] else null),
#"Filtered Rows1" = Table.SelectRows(#"Added Custom2", each [Custom.3] <> null and [Custom.3] <> ""),
#"Removed Columns" = Table.RemoveColumns(#"Filtered Rows1",{"Custom.3"}),
#"Reordered Columns" = Table.ReorderColumns(#"Removed Columns",{"Custom", "Custom.1", "Custom.2", "A"}),
#"Changed Type1" = Table.TransformColumnTypes(#"Reordered Columns",{{"Custom", type text}, {"Custom.1", Int64.Type}, {"Custom.2", Int64.Type}, {"A", type number}}),
#"Grouped Rows" = Table.Group(#"Changed Type1", {"Custom", "Custom.1", "Custom.2"}, {{"A", each List.Sum([A]), type nullable text}}),
#"Changed Type2" = Table.TransformColumnTypes(#"Grouped Rows",{{"Custom", type text}, {"Custom.1", Int64.Type}, {"Custom.2", Int64.Type}, {"A", type number}})
in
#"Changed Type2"