简体   繁体   中英

Connecting two tables that have a many-to-many relationship in powerpivot

I have a question for you guys on how to connect two tables that have a "many-to-many" relationship. Please see the two tables below:

SKU_NO   CATEGORY
sku_1 hair
sku_2 skin
sku_3 hair
CATEGORY   CATEGORY_TYPE
hair type_a
hair type_b
hair type_c
skin type_a
skin type_d

The outpout I would like to have is a table that gives me for each SKU the full list of category types. So for the above two tables the output would be:

SKU_NO    CATEGORY_TYPE
sku_1 type_a
sku_1 type_b
sku_1 type_c
sku_2 type_a
sku_2 type_d
sku_3 type_a
sku_3 type_b
sku_3 type_c

I have been currently trying to do the above by inserting the two tables in powerpivot and adding a dummy table (see below) between them, but with no success. I am open to suggestions - does not have to be in powerpivot but it would be my preferred tool.


在此处输入图像描述

Thanks in advance for your help!

This can't be done in Power Pivot, as you have multiple keys id's in both tables. However this can be done in Power Query, then analyzed in a pivot table.

As your referencing Power Pivot, I'll assume you use Excel 2016.

  1. One at a time, open each of the tables, as PQ data tables -- essentially, open then close them immediately -- you're only trying to get each of them loaded into the Data Model. Ideally (less duplication) you'll want to "load only" not "load and save".

  2. Couple of options here depending on your exact requirements: you can either open, one of the PQ tables, you can select the table by reference (again, less duplication), or just merge the two tables. in PQ "Merge" then select the common (link) data fields

在此处输入图像描述

I included all of the table used here (hopefully) for clarity:

在此处输入图像描述

Hope this works for you.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM