Display a heatmap matrix showing % matches to other table values

digitalx2001

New Member
Joined
Oct 26, 2014
Messages
4
Hi all! First post (but long time lurker!). I've simplified the scenario and sample data I'm trying to solve to the following:

I'm trying to create a heatmap matrix to show percentage of school classes each person was in with every other person. From the raw data (provided below), I want to generate a unique name list, transpose same across the top, do the gradient conditional formatting for high/low values, etc (this isn't the part I need help on).

This issue I'm having is calculating the values. I've somewhat solved this problem but in a very, very ugly and slow way by adding calculated columns to the raw data and then VBA. Code took like 20 minutes to run since there were hundreds of unique names/classes... and this will have to be run often on brand new data sets, so my method is not really sustainable.

As for the solution (required output shown below).... For each cell in the matrix, it should divide the number of classes that RowName <row name="">was in with ColumnName<column name="">, by RowName<row name="">'s total classes.

For example, Bill has 2 classes total (History and Chemistry). Tom was in 1 of those 2 (History). Hence... 1/2 = 50% in cell C2 in the output below. From Tom's perspective, Bill was in all of his classes (1 class, just History). Hence... 1/1 = 100% in cell B3 below.

Really, I think the answer might boil down to just a single formula, but I couldn't find any other similar solutions online to mimic. If VBA would be better suited or required instead of just a repeated formula, that's fine too (and I'll be using VBA to generate the unique list to build the matrix and formatting anyway). Thanks in advance!

EDIT: This would be for Excel 2010+. Might need to run this on different machines, some of which have 2013, so better safe than sorry.

RAW DATA:
NameClass
BillHistory
TomHistory
JoeChemistry
JoeArt
BillChemistry
SallyCalculus
JoeCalculus
JohnHistory
JohnArt

<tbody>
</tbody>

REQUIRED OUTPUT:
ABCDEF
1BillTomJoeSallyJohn
2Bill.5.50.5
3Tom1001
4Joe.3330.333.333
5Sally0010
6John.5.5.50

<tbody>
</tbody>

</row></column></row>
 
Last edited:

Excel Facts

Format cells as time
Select range and press Ctrl+Shift+2 to format cells as time. (Shift 2 is the @ sign).
One way:

Row\Col
A​
B​
C​
D​
E​
F​
G​
1​
Name​
Class​
2​
BillHistory
3​
TomHistory
4​
JoeChemistry
5​
JoeArt
6​
BillChemistry
7​
SallyCalculus
8​
JoeCalculus
9​
JohnHistory
10​
JohnArt
11​
12​
Art​
Calculus​
Chemistry​
History​
13​
Bill
x​
x​
B13 and across and down: {=IF(OR(($A$2:$A$10=$A13)*($B$2:$B$10=B$12)), "x", "")}
14​
Joe
x​
x​
x​
15​
John
x​
x​
16​
Sally
x​
17​
Tom
x​
18​
19​
BillJoeJohnSallyTom
20​
Bill
1​
1​
0​
1​
B20 and across and down: {=IF($A20=B$19, "", SUMPRODUCT((INDEX($B$13:$E$17, MATCH($A20, $A$13:$A$17), 0)="x") * (INDEX($B$13:$E$17, MATCH(B$19, $A$13:$A$17), 0)="x")))}
21​
Joe
1​
1​
1​
0​
22​
John
1​
1​
0​
1​
23​
Sally
0​
1​
0​
0​
24​
Tom
1​
0​
1​
0​
25​
 
Upvote 0
Thanks for the reply. So, maybe I'm missing something - where do we get the percentages from? That's actually the key data: how often RowName is in ColumnName's class, divided by RowName's total classes. Which classes they are in together are completely irrelevant.
 
Upvote 0
Oh wait, this actually is it! I didn't notice because my test data didn't have any people with more than 1 class together. I thought it was only returning a 1 if they had any classes together, but it was actually a count. Perfect!

I got it to work by just adding the following to your code for B20...

{=IF($A20=B$19, "", SUMPRODUCT((INDEX($B$13:$E$17, MATCH($A20, $A$13:$A$17), 0)="x") * (INDEX($B$13:$E$17, MATCH(B$19, $A$13:$A$17), 0)="x"))/COUNTIF($A$2:$A$10,$A20))}
 
Upvote 0

Forum statistics

Threads
1,215,360
Messages
6,124,491
Members
449,166
Latest member
hokjock

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