Using data model and power pivots to link tables in Excel

GeorgeCarter

New Member
Joined
May 26, 2023
Messages
1
Office Version
  1. 365
Platform
  1. Windows
I have three tabs, each with a simple one column table, named respectively, Models, Options, Components. The rows in each table consist of the unique names of the product models, options and components.
r/excel - Using data model and power pivots to link tables in Excel

I have another two tabs, each with a table with two columns that maps various options to each model, and various components to each option respectively.
r/excel - Using data model and power pivots to link tables in Excel

I have added all five tables to the data model and created relationships between the columns with common names (ie model in the Models table and model in the Options to Models mapping table etc).

r/excel - Using data model and power pivots to link tables in Excel

I would like to be able to create a pivot table that lists all the models, along with the options that are mapped to that model, and the components that are mapped to those options. Ultimately, it might look something like this:

r/excel - Using data model and power pivots to link tables in Excel

I have tried creating a pivot table from the data model, but when I add the models, options and components fields to Rows, it shows ALL options for each model and ALL components for each option, rather than just the mapped ones.

Can anyone please tell me where I am going wrong?

Thanks.
 

Excel Facts

How can you automate Excel?
Press Alt+F11 from Windows Excel to open the Visual Basic for Applications (VBA) editor.
I have the same problem with Power Pivot, in general. Any time I establish a relationship between two tables and then create a pivot table, any reports that leverage that relationship return values based on ALL entries instead of limiting the query to the matching values across the related fields.

For example, I have a table that contains various attributes of countries with repeating country names. I created a relationship with a country table that contains demographics of each country. The relationship is one-to-many from the country table (country name) to the attributes table (country name), as expected. But when I try to create a pivot table with the name of the country from table1 along with the population from table2, I instead get the same exact population for every country, which is the sum of all of the populations of all the countries.

Please help!
 
Upvote 0
That is not the same problem as the OP here at all (which was simply down to there not being a value field in the pivot table, as far as I can see). Your issue is that your relationships are the wrong way round for what you are doing. If you need them the way you have them, then you will need to write measures in DAX to return the values you need, rather than relying on the implicit sum measures that are available by default.
 
Upvote 1
Unless I'm missing something (which would NOT be unusual!), to me it looks like you only need the three pretty color tables into Power Query and then do this:
Power Query:
let
    Source = Excel.CurrentWorkbook(){[Name="Models"]}[Content],
    AddedOptions = Table.AddColumn(Source, "Options", each Options),
    ExpandedOptions = Table.ExpandTableColumn(AddedOptions, "Options", {"Options"}, {"Options"}),
    AddedComponents = Table.AddColumn(ExpandedOptions, "Components", each Components),
    ExpandedComponents = Table.ExpandTableColumn(AddedComponents, "Components", {"Components"}, {"Components"}),
    ChangedType = Table.TransformColumnTypes(ExpandedComponents,{{"Models", type text}, {"Options", type text}, {"Components", type text}})
in
    ChangedType
That results in a table that looks like this:
Book1
GHI
1ModelsOptionsComponents
2Model AOption 1Component 1
3Model AOption 1Component 2
4Model AOption 1Component 3
5Model AOption 1Component 4
6Model AOption 1Component 5
7Model AOption 1Component 6
8Model AOption 1Component 7
9Model AOption 1Component 8
10Model AOption 1Component 9
11Model AOption 1Component 10
12Model AOption 2Component 1
13Model AOption 2Component 2
14Model AOption 2Component 3
15Model AOption 2Component 4
16Model AOption 2Component 5
17Model AOption 2Component 6
18Model AOption 2Component 7
19Model AOption 2Component 8
20Model AOption 2Component 9
21Model AOption 2Component 10
Sheet1

which isn't needed but I posted it to give you an idea of what's in the final table. It can just be loaded to a Pivot Table that looks like this:
Book1
OPQ
6ModelsOptionsComponents
7Model AOption 1Component 1
8Component 10
9Component 2
10Component 3
11Component 4
12Component 5
13Component 6
14Component 7
15Component 8
16Component 9
17Option 1 Total
18Option 10Component 1
19Component 10
20Component 2
21Component 3
22Component 4
23Component 5
24Component 6
25Component 7
26Component 8
27Component 9
28Option 10 Total
29Option 2Component 1
30Component 10
31Component 2
Sheet1

That is copied from the actual pivot table - XL2BB won't copy a Pivot Table!.
BTW, the pics are very pretty, especially around Easter time, but XL2BB would be more helpful - even if I'm completely off base here!
 
Upvote 0

Forum statistics

Threads
1,223,898
Messages
6,175,274
Members
452,628
Latest member
dd2

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