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
 
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.
Thank you, Alan! I am far away from Amazon, but will try my best to get it
 
Upvote 0

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
I've managed to find it, but you're right, it's easier here for sure :)
 
Upvote 0
Create Table Sales and Stock

Ribbon Data > Get data > From Table
Power Query Home > Advanced editor

Paste below code

Power Query:
let
    Stock = Excel.CurrentWorkbook(){[Name="Stock"]}[Content],
    Sales = Table.RenameColumns(Excel.CurrentWorkbook(){[Name="Sales"]}[Content],{{"Delivery price", "Delivery price1"}, {"Sale price", "Sale price1"}}),
    #"Appended Query" = Table.Combine({Stock, Sales}),
    #"Unpivoted Other Columns" = Table.UnpivotOtherColumns(#"Appended Query", {"Art ID", "Name", "Category"}, "Attribute", "Value"),
    #"Removed Duplicates" = Table.Distinct(#"Unpivoted Other Columns"),
    #"Pivoted Column" = Table.Pivot(#"Removed Duplicates", List.Distinct(#"Removed Duplicates"[Attribute]), "Attribute", "Value"),
    #"Sorted Rows" = Table.Sort(#"Pivoted Column",{{"Unit", Order.Descending}, {"Category", Order.Ascending}})
in
    #"Sorted Rows"




Book1
ABCDEFGHIJKLMN
34Art IDNameCategoryUnitStockDelivery priceSale priceMarkupSubgroupGroupQtySale price1Delivery price1Supplier
355849Product 01Cat01pcs.10.6011110.8948.059177Subgr01Group0110.890.601111Suppl 001
3625578Product 106Cat101pcs.-11.282.4994.53125Subgr01Group01
3725577Product 105Cat101pcs.01.282.4994.53125Subgr01Group01
3825575Product 103Cat101pcs.01.2398571.2-3.214645Subgr01Group01
395850Product 101Cat101pcs.00.6011110.9558.040695Subgr01Group01
405851Product 102Cat101pcs.10.6011110.8948.059177Subgr01Group01
4125576Product 104Cat101pcs.01.2400722.49100.794793Subgr01Group01
4243275Product 107Cat103pcs.355.872.9930.806452Subgr01Group01
4343281Product 02Cat01128.9922.044Suppl 002
4423689Product 03Cat0211.691.1425Suppl 003
4523691Product 04Cat0323.382.286Suppl 004
4623690Product 05Cat0311.491.143Suppl 005
Sheet1
 
Upvote 0

Forum statistics

Threads
1,223,705
Messages
6,173,989
Members
452,541
Latest member
haasro02

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