Combine two data sets. Pivot Table?

wakerider017

Board Regular
Joined
Jun 10, 2015
Messages
77
Hey guys, I have two data sets that I want to combine. Data is currently on two different worksheets.

Below is an example of what I am trying to do, but my actual data has more columns for both Opportunity and Contacts. I also have many more rows.

[TABLE="width: 211"]
<colgroup><col style="text-align: center;"><col span="2" style="text-align: center;"></colgroup><tbody>[TR]
[TD="align: center"]Opportunity[/TD]
[TD="align: center"]Account [/TD]
[TD="align: center"]Stage[/TD]
[/TR]
[TR]
[TD="align: center"]1[/TD]
[TD="align: center"]1[/TD]
[TD="align: center"]Open[/TD]
[/TR]
[TR]
[TD="align: center"]2[/TD]
[TD="align: center"]2[/TD]
[TD="align: center"]Closed[/TD]
[/TR]
[TR]
[TD="align: center"]3[/TD]
[TD="align: center"]3[/TD]
[TD="align: center"]Open[/TD]
[/TR]
[TR]
[TD="align: center"]4[/TD]
[TD="align: center"]1[/TD]
[TD="align: center"]Open[/TD]
[/TR]
[TR]
[TD="align: center"]5[/TD]
[TD="align: center"]2[/TD]
[TD="align: center"]Closed[/TD]
[/TR]
</tbody>[/TABLE]


[TABLE="width: 211"]
<colgroup><col style="text-align: center;"><col span="2" style="text-align: center;"></colgroup><tbody>[TR]
[TD="align: center"]Contact[/TD]
[TD="align: center"]Account[/TD]
[TD="align: center"]Name[/TD]
[/TR]
[TR]
[TD="align: center"]1[/TD]
[TD="align: center"]3[/TD]
[TD="align: center"]Bob[/TD]
[/TR]
[TR]
[TD="align: center"]2[/TD]
[TD="align: center"]2[/TD]
[TD="align: center"]John[/TD]
[/TR]
[TR]
[TD="align: center"]3[/TD]
[TD="align: center"]1[/TD]
[TD="align: center"]Mary[/TD]
[/TR]
[TR]
[TD="align: center"]4[/TD]
[TD="align: center"]3[/TD]
[TD="align: center"]Tina[/TD]
[/TR]
[TR]
[TD="align: center"]5[/TD]
[TD="align: center"]1[/TD]
[TD="align: center"]Tim[/TD]
[/TR]
</tbody>[/TABLE]



I need to link them by the Account number.
Ideally I'd like a hierarchy, where each Opportunity has its own row and lists all the related contacts underneath. Not sure how to do that? Can this be done in a pivot table

Thinking output would be something like this:

[TABLE="width: 211"]
<colgroup><col><col span="2"></colgroup><tbody>[TR]
[TD="align: center"]Opportunity[/TD]
[TD="align: center"]Account [/TD]
[TD="align: center"]Stage[/TD]
[/TR]
[TR]
[TD="align: center"]1[/TD]
[TD="align: center"]1[/TD]
[TD="align: center"]Open[/TD]
[/TR]
[TR]
[TD="align: center"]Contact[/TD]
[TD="align: center"]Account[/TD]
[TD="align: center"]Name[/TD]
[/TR]
[TR]
[TD="align: center"]3[/TD]
[TD="align: center"]1[/TD]
[TD="align: center"]Mary[/TD]
[/TR]
[TR]
[TD="align: center"]5[/TD]
[TD="align: center"]1[/TD]
[TD="align: center"]Tim[/TD]
[/TR]
[TR]
[TD="align: center"]Opportunity[/TD]
[TD="align: center"]Account [/TD]
[TD="align: center"]Stage[/TD]
[/TR]
[TR]
[TD="align: center"]2[/TD]
[TD="align: center"]2[/TD]
[TD="align: center"]Closed[/TD]
[/TR]
[TR]
[TD="align: center"]Contact[/TD]
[TD="align: center"]Account[/TD]
[TD="align: center"]Name[/TD]
[/TR]
[TR]
[TD="align: center"]2[/TD]
[TD="align: center"]2[/TD]
[TD="align: center"]John[/TD]
[/TR]
[TR]
[TD="align: center"]Opportunity[/TD]
[TD="align: center"]Account [/TD]
[TD="align: center"]Stage[/TD]
[/TR]
[TR]
[TD="align: center"]3[/TD]
[TD="align: center"]3[/TD]
[TD="align: center"]Open[/TD]
[/TR]
[TR]
[TD="align: center"]Contact[/TD]
[TD="align: center"]Account[/TD]
[TD="align: center"]Name[/TD]
[/TR]
[TR]
[TD="align: center"]1[/TD]
[TD="align: center"]3[/TD]
[TD="align: center"]Bob[/TD]
[/TR]
[TR]
[TD="align: center"]4[/TD]
[TD="align: center"]3[/TD]
[TD="align: center"]Tina[/TD]
[/TR]
[TR]
[TD="align: center"]Opportunity[/TD]
[TD="align: center"]Account [/TD]
[TD="align: center"]Stage[/TD]
[/TR]
[TR]
[TD="align: center"]4[/TD]
[TD="align: center"]1[/TD]
[TD="align: center"]Open[/TD]
[/TR]
[TR]
[TD="align: center"]Contact[/TD]
[TD="align: center"]Account[/TD]
[TD="align: center"]Name[/TD]
[/TR]
[TR]
[TD="align: center"]3[/TD]
[TD="align: center"]1[/TD]
[TD="align: center"]Mary[/TD]
[/TR]
[TR]
[TD="align: center"]5[/TD]
[TD="align: center"]1[/TD]
[TD="align: center"]Tim[/TD]
[/TR]
[TR]
[TD="align: center"]Opportunity[/TD]
[TD="align: center"]Account [/TD]
[TD="align: center"]Stage[/TD]
[/TR]
[TR]
[TD="align: center"]5[/TD]
[TD="align: center"]2[/TD]
[TD="align: center"]Closed[/TD]
[/TR]
[TR]
[TD="align: center"]Contact[/TD]
[TD="align: center"]Account[/TD]
[TD="align: center"]Name[/TD]
[/TR]
[TR]
[TD="align: center"]2[/TD]
[TD="align: center"]2[/TD]
[TD="align: center"]John[/TD]
[/TR]
</tbody>[/TABLE]
 

Excel Facts

When did Power Query debut in Excel?
Although it was an add-in in Excel 2010 & Excel 2013, Power Query became a part of Excel in 2016, in Data, Get & Transform Data.
maybe something like this with PowerQuery

[Table="width:, class:head"]
[tr=bgcolor:#FFFFFF][td=bgcolor:#5B9BD5]Opportunity[/td][td=bgcolor:#5B9BD5]Account[/td][td=bgcolor:#5B9BD5]Stage[/td][td][/td][td=bgcolor:#5B9BD5]Contact[/td][td=bgcolor:#5B9BD5]Account[/td][td=bgcolor:#5B9BD5]Name[/td][td][/td][td=bgcolor:#70AD47]Opportunity[/td][td=bgcolor:#70AD47]Account[/td][td=bgcolor:#70AD47]Stage[/td][td=bgcolor:#70AD47]Contact[/td][td=bgcolor:#70AD47]Account.1[/td][td=bgcolor:#70AD47]Name[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#DDEBF7]
1​
[/td][td=bgcolor:#DDEBF7]
1​
[/td][td=bgcolor:#DDEBF7]Open[/td][td][/td][td=bgcolor:#DDEBF7]
1​
[/td][td=bgcolor:#DDEBF7]
3​
[/td][td=bgcolor:#DDEBF7]Bob[/td][td][/td][td=bgcolor:#E2EFDA]
1​
[/td][td=bgcolor:#E2EFDA]
1​
[/td][td=bgcolor:#E2EFDA]Open[/td][td=bgcolor:#E2EFDA]
3​
[/td][td=bgcolor:#E2EFDA]
1​
[/td][td=bgcolor:#E2EFDA]Mary[/td][/tr]

[tr=bgcolor:#FFFFFF][td]
2​
[/td][td]
2​
[/td][td]Closed[/td][td][/td][td]
2​
[/td][td]
2​
[/td][td]John[/td][td][/td][td]
1​
[/td][td]
1​
[/td][td]Open[/td][td]
5​
[/td][td]
1​
[/td][td]Tim[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#DDEBF7]
3​
[/td][td=bgcolor:#DDEBF7]
3​
[/td][td=bgcolor:#DDEBF7]Open[/td][td][/td][td=bgcolor:#DDEBF7]
3​
[/td][td=bgcolor:#DDEBF7]
1​
[/td][td=bgcolor:#DDEBF7]Mary[/td][td][/td][td=bgcolor:#E2EFDA]
4​
[/td][td=bgcolor:#E2EFDA]
1​
[/td][td=bgcolor:#E2EFDA]Open[/td][td=bgcolor:#E2EFDA]
3​
[/td][td=bgcolor:#E2EFDA]
1​
[/td][td=bgcolor:#E2EFDA]Mary[/td][/tr]

[tr=bgcolor:#FFFFFF][td]
4​
[/td][td]
1​
[/td][td]Open[/td][td][/td][td]
4​
[/td][td]
3​
[/td][td]Tina[/td][td][/td][td]
4​
[/td][td]
1​
[/td][td]Open[/td][td]
5​
[/td][td]
1​
[/td][td]Tim[/td][/tr]

[tr=bgcolor:#FFFFFF][td=bgcolor:#DDEBF7]
5​
[/td][td=bgcolor:#DDEBF7]
2​
[/td][td=bgcolor:#DDEBF7]Closed[/td][td][/td][td=bgcolor:#DDEBF7]
5​
[/td][td=bgcolor:#DDEBF7]
1​
[/td][td=bgcolor:#DDEBF7]Tim[/td][td][/td][td=bgcolor:#E2EFDA]
3​
[/td][td=bgcolor:#E2EFDA]
3​
[/td][td=bgcolor:#E2EFDA]Open[/td][td=bgcolor:#E2EFDA]
1​
[/td][td=bgcolor:#E2EFDA]
3​
[/td][td=bgcolor:#E2EFDA]Bob[/td][/tr]

[tr=bgcolor:#FFFFFF][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td]
3​
[/td][td]
3​
[/td][td]Open[/td][td]
4​
[/td][td]
3​
[/td][td]Tina[/td][/tr]

[tr=bgcolor:#FFFFFF][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td=bgcolor:#E2EFDA]
2​
[/td][td=bgcolor:#E2EFDA]
2​
[/td][td=bgcolor:#E2EFDA]Closed[/td][td=bgcolor:#E2EFDA]
2​
[/td][td=bgcolor:#E2EFDA]
2​
[/td][td=bgcolor:#E2EFDA]John[/td][/tr]

[tr=bgcolor:#FFFFFF][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td][/td][td]
5​
[/td][td]
2​
[/td][td]Closed[/td][td]
2​
[/td][td]
2​
[/td][td]John[/td][/tr]
[/table]


Code:
[SIZE=1]let
    Source = Table.NestedJoin(Table1,{"Account"},Table2,{"Account"},"Table2",JoinKind.FullOuter),
    #"Expanded Table2" = Table.ExpandTableColumn(Source, "Table2", {"Contact", "Account", "Name"}, {"Contact", "Account.1", "Name"})
in
    #"Expanded Table2"[/SIZE]
 
Upvote 0

Forum statistics

Threads
1,224,823
Messages
6,181,177
Members
453,021
Latest member
Justyna P

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