Combine 3 tables into 1 Pivot Table using Data Model based on common Date?

StrawberryDreams

New Member
Joined
Mar 26, 2022
Messages
38
Office Version
  1. 365
Platform
  1. Windows
  2. MacOS
  3. Mobile
As the title suggests I would like to combine 3 different tables into one pivot table.

I have looked at the Data Model and have created Connections and Relationships but it doesn't seem to work. As it will just average values for dates that might not have data in each table. How can I do this ? I also only have excel 2016, so I do not currently have access to power pivot if this would make it easier.

Screenshot 2023-02-20 124639.jpg
 

Attachments

  • 1676925811237.png
    1676925811237.png
    31.1 KB · Views: 8

Excel Facts

Control Word Wrap
Press Alt+Enter to move to a new row in a cell. Lets you control where the words wrap.
Based upon the information shown, what would your mocked up solution look like?
 
Upvote 0
Using Power Query. Loaded each table to PQ Editor. Joined each on common field Date with a full outer join. Then applied the following Mcode

Power Query:
let
    Source = Table.NestedJoin(Merge1, {"Date"}, Table4, {"Date"}, "Table4", JoinKind.FullOuter),
    #"Expanded Table4" = Table.ExpandTableColumn(Source, "Table4", {"Date", "Color", "weight"}, {"Date.2", "Color", "weight"}),
    #"Added Custom" = Table.AddColumn(#"Expanded Table4", "Custom", each if [Date] = null then [Date.1] else [Date]),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "Custom.1", each if [Custom] = null then [Date.2] else [Custom]),
    #"Removed Other Columns" = Table.SelectColumns(#"Added Custom1",{"Custom.1", "weight", "Color", "Amount", "PO#", "Value", "Product", "Date"}),
    #"Removed Columns" = Table.RemoveColumns(#"Removed Other Columns",{"Date"}),
    #"Sorted Rows" = Table.Sort(#"Removed Columns",{{"Custom.1", Order.Ascending}}),
    #"Reordered Columns" = Table.ReorderColumns(#"Sorted Rows",{"Custom.1", "Product", "Value", "PO#", "Amount", "Color", "weight"})
in
    #"Reordered Columns"


Book4
ABCDEFGHIJKLM
1DateProductValueDatePO#AmountDateColorweight
21-JanHat202-Jan123441-Janred30
34-JanShirt504-Jan234535-Janblue20
410-JanPants80
5Custom.1ProductValuePO#AmountColorweight
644927Hat20red30
74492812344
844930Shirt5023453
944931blue20
1044936Pants80
Sheet1
 
Upvote 0
Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at: Combine 3 tables into 1 Pivot Table using Data Model based on common Dates ?
There is no need to repeat the link(s) provided above but if you have posted the question at other places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
 
Upvote 0
Hi Alan,

Thank you for the tips. I have never used PQ, so I will look into how to apply what you wrote. By the way, is this method dynamic, in that if I add to any of those three tables the merged PQ table will update ?
 
Upvote 0
Using Power Query. Loaded each table to PQ Editor. Joined each on common field Date with a full outer join. Then applied the following Mcode

Power Query:
let
    Source = Table.NestedJoin(Merge1, {"Date"}, Table4, {"Date"}, "Table4", JoinKind.FullOuter),
    #"Expanded Table4" = Table.ExpandTableColumn(Source, "Table4", {"Date", "Color", "weight"}, {"Date.2", "Color", "weight"}),
    #"Added Custom" = Table.AddColumn(#"Expanded Table4", "Custom", each if [Date] = null then [Date.1] else [Date]),
    #"Added Custom1" = Table.AddColumn(#"Added Custom", "Custom.1", each if [Custom] = null then [Date.2] else [Custom]),
    #"Removed Other Columns" = Table.SelectColumns(#"Added Custom1",{"Custom.1", "weight", "Color", "Amount", "PO#", "Value", "Product", "Date"}),
    #"Removed Columns" = Table.RemoveColumns(#"Removed Other Columns",{"Date"}),
    #"Sorted Rows" = Table.Sort(#"Removed Columns",{{"Custom.1", Order.Ascending}}),
    #"Reordered Columns" = Table.ReorderColumns(#"Sorted Rows",{"Custom.1", "Product", "Value", "PO#", "Amount", "Color", "weight"})
in
    #"Reordered Columns"


Book4
ABCDEFGHIJKLM
1DateProductValueDatePO#AmountDateColorweight
21-JanHat202-Jan123441-Janred30
34-JanShirt504-Jan234535-Janblue20
410-JanPants80
5Custom.1ProductValuePO#AmountColorweight
644927Hat20red30
74492812344
844930Shirt5023453
944931blue20
1044936Pants80
Sheet1

Hi Alan,

I merged Product with Po, then expanded, then merged that with Color to get them all into one table. After that I opened advanced editor and pasted your Mcode and pressed enter and received this error :

Screenshot 2023-02-21 110033.jpg


Not sure what I might have done wrong.
 
Upvote 0
Cross-posting (posting the same question in more than one forum) is not against our rules, but the method of doing so is covered by #13 of the Forum Rules.

Be sure to follow & read the link at the end of the rule too!

Cross posted at: Combine 3 tables into 1 Pivot Table using Data Model based on common Dates ?
There is no need to repeat the link(s) provided above but if you have posted the question at other places, please provide links to those as well.

If you do cross-post in the future and also provide links, then there shouldn’t be a problem.
Hi Peter,

Sorry about that. I originally posted here first and wasn't aware about cross posting issues - so thanks. I did post in the other forum since I initially thought I wouldn't get a reply.

Combine 3 tables into 1 Pivot Table using Data Model based on common Dates ?
 
Upvote 0
Not sure what that message means. You may want to google it. Did you name your tables the same as those in the Mcode. It may also be a case of field names that have been renamed not in sync with yours.
 
Upvote 0

Forum statistics

Threads
1,214,983
Messages
6,122,598
Members
449,089
Latest member
Motoracer88

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