Power Query - Relationship Query

haddy

New Member
Joined
Sep 3, 2014
Messages
22
Hi,

Apologies if this has (probably) been raised, but i wasn't sure what you'd call it.

I've got three spreadsheets/tables;
Sales
SaleProductItemQuantityCost
1​
ProductA
1​
50​
2​
ProductB
1​
50​
3​
ProductA
2​
100​

ProductDefine
ProductItemProductQuantity
ProductAX1
2​
ProductAX2
2​
ProductAX3
2​
ProductBX1
1​
ProductBX4
2​
ProductBX5
1​

Stocking
ProductQuantityCost
X1
100​
50​
X2
50​
100​
X3
75​
25​
X4
20​
20​
X5
15​
25​

Barely have foundational understanding of how Power Query can work (other than watching Youtube videos make it look easy) - I'm trying to have the spreadsheet register that there's a link between ProductItem(Sales) and Product(ProductDefine), and once the link has been established I'm guessing I'll be able to use PowerPivot to show me the following (based on the above example);
ProductQuantity
X1
7​
X2
6​
X3
6​
X4
2​
X5
1​

Eventually I'd like the last table (Stocking) to have a link with the other two tables - I was thinking of using the 'Product' column.

So far I've come to dead end with 'duplicate values' between two tables. I'm lead to believe ProductItem is the issue?

Hope I've made sense

Thank you in advance
 

Excel Facts

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Sorry Admin - I realised I hadn't completed the thread title, and now I can't edit the post

'Power Query - Relationship Query'
 
Upvote 0
In your simplified example, can you explain the logic of how you arrived at the quantities in the solution Table. I cannot see how these quantities were arrived at with the data provided. Please clarify so that we can move onto a working solution.
 
Upvote 0
Hi Alan and thank you for the reply.

The last table might be causing some confusion (Stocking) - please disregard for the solution on the bottom. As mentioned, I'd like to have it linked to the other tables, but I'm working with the first issue. (Though I won't say no to an all encompassing solution)

I'm trying to get the model to understand that there're multiple "sub-products" (defined in 'ProductDefine' table) to a ProductItem (in Sales). So in the above example ProductA consist of 3 sub-products with varying quantities - same with ProductB. There are some sub-products which both ProductItems (ProductA & B) use - in this example its X1.

Hope that helps
 
Upvote 0
It would be helpful to understand the relationship between tables if you showed us a mocked up solution. Obviously, the one you have provided bears no relationship to the tables shown. So I ask again, so that I am clear. Show us a mocked up solution using the example tables you have provided.
 
Upvote 0
If this is the solution you are looking for, then advise and I will provide you with mcode. If different, then please show what you want.

Book13
AB
1ProductSum X
2X13
3X22
4X32
5X42
6X51
Sheet3


Book13
ABCD
1ProductSum XTable3.QuantityTable3.Cost
2X1310050
3X2250100
4X327525
5X422020
6X511525
Sheet6
 
Upvote 0
Example.PNG


I don't believe so Alan. I think I'm confusing you with the third table (Stocking) - I've attached a mockup which hopefully explains what I'm trying to figure out.

This example may help your understanding as well;
Imagine ProductA is a food box which contains (or defined to include) 2 apples (X1), 2 oranges (X2) and 2 bananas (X3).
ProductB is another food box also with 1 apple (X1), 2 melons (X4) and 1 strawberry (X5).

If I order 3 ProductAs and 1 ProductB - I should end up with 7 apples (X1), 6 oranges (X2), 6 bananas (X3), 2 melons (X4) and 1 strawberry (X5).

Edit: I adjusted the column header in ProductDefine (Quantity to ProductQuantity) assuming they should be different if ProductItem should be the key between the two tables (?)
 
Last edited:
Upvote 0
If you want a link between two data tables its easiest to do so in PowerPivot where you can define the relationship:

from PowerPivot Ribbon, select Manage then 'Diagram View' drag between the linked fields.
then create a pivot table and put the relevant fields in columns/rows and values sections.

I find this an easy way of joining data sets, but it does depend on the data.

HTH
 
Upvote 0
I really don't want to have to re-type all your data to give you an answer. Please use XL2BB to upload your data so that it can be manipulated without issue. We cannot manipulate data that are in pictures.
 
Upvote 0
I really don't want to have to re-type all your data to give you an answer. Please use XL2BB to upload your data so that it can be manipulated without issue. We cannot manipulate data that are in pictures.

Hope this works as you've requested - first time using this.

Example.xlsx
ABCDEFGHIJKLMNO
4SaleProductItemQuantityCostProductItemProductProductQuantityProductItemProductProductQuantityProductQuantity
51ProductA150ProductAX12ProductAX12X17
62ProductB150ProductAX22ProductAX22X26
73ProductA2100ProductAX32ProductAX32X36
8ProductBX11ProductBX11X42
9ProductBX42ProductBX42X51
10ProductBX51ProductBX51
11ProductAX12
12ProductAX22
13ProductAX32
14ProductAX12
15ProductAX22
16ProductAX32
Sheet1
 
Upvote 0

Forum statistics

Threads
1,215,480
Messages
6,125,047
Members
449,206
Latest member
Healthydogs

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