Excel Power query - is it possible at all to resolve such Pivot/Merge/Union

mirusev

New Member
Joined
Oct 14, 2018
Messages
20
Office Version
  1. 365
Platform
  1. Windows
It is two files based query - I do not know how to call it - Pivot/Union or other...
The first source is at rows 1 to 6, the second one is from 8 to 16 and the wanted result is at rows 18 to 30. Could it be done with Power query? Any hint of the relations/methods needed will be of great help - I did it partially but not as a whole solution to get that result.



Here is the table:

sample-sales-nal.xlsx
ABCDEFGHIJKLMNO
1Art IDNameQtySale priceDelivery priceSupplierCategorySales data
25849Product 0110.890.60Suppl 001Cat01
3043281Product 02128.9922.04Suppl 002Cat01
4023689Product 0311.691.14Suppl 003Cat02
5023691Product 0423.382.29Suppl 004Cat03
6023690Product 0511.491.14Suppl 005Cat03
7
8Art IDNameUnitStockDelivery priceSale priceMarkupSubgroupGroupCategoryStock data
95849Product 01pcs.10.6011110.8948.05918Subgr01Group01Cat01
105850Product 101pcs.00.6011110.9558.0407Subgr01Group01Cat101
115851Product 102pcs.10.6011110.8948.05918Subgr01Group01Cat101
12025575Product 103pcs.01.2398571.2-3.21465Subgr01Group01Cat101
13025576Product 104pcs.01.2400722.49100.7948Subgr01Group01Cat101
14025577Product 105pcs.01.282.4994.53125Subgr01Group01Cat101
15025578Product 106pcs.-11.282.4994.53125Subgr01Group01Cat101
16043275Product 107pcs.355.872.9930.80645Subgr01Group01Cat103
17
18Art IDNameUnitStockDelivery priceSale priceMarkupSubgroupGroupCategoryQtySale priceDelivery priceSupplierMerge/Unite/Pivot ?????
195849Product 01pcs.10.6011110.8948.05918Subgr01Group01Cat0110.890.60Suppl 001
205850Product 101pcs.00.6011110.9558.0407Subgr01Group01Cat101
215851Product 102pcs.10.6011110.8948.05918Subgr01Group01Cat101
22025575Product 103pcs.01.2398571.2-3.21465Subgr01Group01Cat101
23025576Product 104pcs.01.2400722.49100.7948Subgr01Group01Cat101
24025577Product 105pcs.01.282.4994.53125Subgr01Group01Cat101
25025578Product 106pcs.-11.282.4994.53125Subgr01Group01Cat101
26043275Product 107pcs.355.872.9930.80645Subgr01Group01Cat103
27043281Product 02Cat01128.9922.04Suppl 002
28023689Product 03Cat0211.691.14Suppl 003
29023691Product 04Cat0323.382.29Suppl 004
30023690Product 05Cat0311.491.14Suppl 005
sales
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
is this acceptable?

Art IDNameUnitStockDelivery priceSale priceMarkupSubgroupGroupCategoryQtySupplier
5849Product 01pcs.10.6011110.8948.059177Subgr01Group01Cat011Suppl 001
5850Product 101pcs.00.6011110.9558.040695Subgr01Group01Cat101
5851Product 102pcs.10.6011110.8948.059177Subgr01Group01Cat101
25575Product 103pcs.01.2398571.2-3.214645Subgr01Group01Cat101
25576Product 104pcs.01.2400722.49100.794793Subgr01Group01Cat101
25577Product 105pcs.01.282.4994.53125Subgr01Group01Cat101
25578Product 106pcs.-11.282.4994.53125Subgr01Group01Cat101
43275Product 107pcs.355.872.9930.806452Subgr01Group01Cat103
23689Product 031.14251.69Cat021Suppl 003
23690Product 051.1431.49Cat031Suppl 005
23691Product 042.2863.38Cat032Suppl 004
43281Product 0222.04428.99Cat011Suppl 002
 
Last edited:
Upvote 0
here:

Power Query:
let
    Sales = Excel.CurrentWorkbook(){[Name="Sales"]}[Content],
    Stock = Excel.CurrentWorkbook(){[Name="Stock"]}[Content],
    Source = Table.Combine({Sales, Stock}),
    Grp = Table.Group(Source, {"Art ID", "Sale price", "Delivery price", "Category"}, {{"Count", each _, type table}}),
    LQty = Table.AddColumn(Grp, "Qty", each List.Distinct([Count][Qty])),
    ExQty = Table.TransformColumns(LQty, {"Qty", each Text.Combine(List.Transform(_, Text.From), ","), type text}),
    LSupplier = Table.AddColumn(ExQty, "Supplier", each List.Distinct([Count][Supplier])),
    ExSupplier = Table.TransformColumns(LSupplier, {"Supplier", each Text.Combine(List.Transform(_, Text.From), ","), type text}),
    LUnit = Table.AddColumn(ExSupplier, "Unit", each List.Distinct([Count][Unit])),
    ExUnit = Table.TransformColumns(LUnit, {"Unit", each Text.Combine(List.Transform(_, Text.From), ","), type text}),
    LStock = Table.AddColumn(ExUnit, "Stock", each List.Distinct([Count][Stock])),
    ExStock = Table.TransformColumns(LStock, {"Stock", each Text.Combine(List.Transform(_, Text.From), ","), type text}),
    LMarkup = Table.AddColumn(ExStock, "Markup", each List.Distinct([Count][Markup])),
    ExMarkup = Table.TransformColumns(LMarkup, {"Markup", each Text.Combine(List.Transform(_, Text.From), ","), type text}),
    LSubgroup = Table.AddColumn(ExMarkup, "Subgroup", each List.Distinct([Count][Subgroup])),
    ExSubgroup = Table.TransformColumns(LSubgroup, {"Subgroup", each Text.Combine(List.Transform(_, Text.From), ","), type text}),
    LGroup = Table.AddColumn(ExSubgroup, "Group", each List.Distinct([Count][Group])),
    ExGroup = Table.TransformColumns(LGroup, {"Group", each Text.Combine(List.Transform(_, Text.From), ","), type text}),
    LName = Table.AddColumn(ExGroup, "Name", each List.Distinct([Count][Name])),
    ExName = Table.TransformColumns(LName, {"Name", each Text.Combine(List.Transform(_, Text.From), ","), type text}),
    Reorder = Table.ReorderColumns(ExName,{"Art ID", "Name", "Unit", "Stock", "Delivery price", "Sale price", "Markup", "Subgroup", "Group", "Category", "Qty", "Supplier", "Count"}),
    Sort = Table.Sort(Reorder,{{"Unit", Order.Descending}, {"Name", Order.Ascending}, {"Art ID", Order.Ascending}})
in
    Sort
 
Last edited:
Upvote 0

Thank you very much!

I know, no shortcut to the knowledge but if you know where I could see it (the important parts) making it with the GUI will be great - some book, site, blog...? :)

And thanks again!
 
Upvote 0
To become better at PQ, you may wish to get the book, "M is for (Data) Monkey" by Ken Puls and Miguel Escobar. Available on Amazon.
 
Upvote 0

Forum statistics

Threads
1,215,764
Messages
6,126,750
Members
449,335
Latest member
Tanne

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