Pairwise Comparison Table

Samgraphics

Board Regular
Joined
Jan 9, 2022
Messages
61
Office Version
  1. 2011
Platform
  1. MacOS
Hi, I'm trying to create a pairwise/tripple-wise comparison table in Excel. I checked ChatGPT but the solution it gave me isn't working. Can anyone help me? I'm comparing the correlation analysis between numbers to determine if any pairs or sets of numbers tend to appear together more often and then highlight pairs with high correlation coefficients.

ChatGPT suggested
In Sheet1 enter my lotter data.
in a new sheet2, create a grid where rows and columns represent the numbers (1 to 35). start by listing numbers 1 to 35 down column A and across row 1.I will have numbers 1 to 35 in cells A2 to A36 and in cells B1 to AJ1.

Then in Sheet2 B2 enter this formula =SUMPRODUCT((Sheet1!$B$2:$F$100=$A2)*(Sheet1!$B$2:$F$100=B$1))

But this isn't working.

This is the data

LOTTERY ANALYSIS.xlsx
ABCDEFGH
1Draw #P1P2P3P4P5B1B2
21311192933312
328914252946
43317222628712
54713162532911
6510121324251112
761321252832210
8771013283145
98267815710
1092417202718
111021621232718
12115813263559
131245182230512
141322426303467
15144101827321012
16156816202478
1716113222631210
1817714232529211
191879101524412
20194610112579
21205618283027
Sheet2



This is the comparison table (I only copied part of it to reduce size.)

LOTTERY ANALYSIS.xlsx
ABCDEFGHIJK
112345678910
211000000
320400000
430020000
540004000
650000300
760000040
870000005
980000000
1090000000
11100000000
12110000000
13120000000
14130000000
15140000000
16150000000
17160000000
18170000000
19180000000
20190000000
21200000000
22210000000
23220000000
24230000000
2524
2625
2726
2827
2928
3029
Sheet3
Cell Formulas
RangeFormula
B2:H24B2=SUMPRODUCT((Sheet2!$B$2:$F$100=B$1)*(Sheet2!$B$2:$F$100=$A2))


pleaes help.
Thank you
 

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
I don't think it will be easy with formulas. especially having in mind you have a bit older version of Excel.

Such a macro will do the job in almost no-time.
VBA Code:
Sub pairs_frq_table()
Dim i As Long, j As Long, k As Long, lr As Long
Dim src As Variant, outp(1 To 35, 1 To 35) As Long
lr = Cells(Rows.Count, 1).End(xlUp).Row
src = Range(Cells(2, 2), Cells(lr, 8)).Value
For i = 1 To lr - 1
  For j = 1 To 6
    For k = j + 1 To 7
      outp(src(i, j), src(i, k)) = outp(src(i, j), src(i, k)) + 1
      outp(src(i, k), src(i, j)) = outp(src(i, j), src(i, k))
    Next k
  Next j
Next i
Range("K2").Resize(35, 35).Value = outp
End Sub

You may add 1:35 to verical and horizontal headers of output table manually. and when you add new rows of lottery results, just rerun the macro. It will replace the results.

From the point of view of calculations - triplets will be not much more work, but how would you like to present them? the result will be no sqare (2D) table, but a cube (3D). Of course it is possible to list all triplets in a list (1-D table)
1-2-3 ; count of 1-2-3
1-2-4 ; count of 1-2-4
and so on, but then we shall probably not allow for listing all 6 identical results for
1-2-3
1-3-2
2-1-3
2-3-1
3-1-2
3-2-1
and that makes programming somewhat harder
 
Upvote 0
Solution
I don't think it will be easy with formulas. especially having in mind you have a bit older version of Excel.

Such a macro will do the job in almost no-time.
VBA Code:
Sub pairs_frq_table()
Dim i As Long, j As Long, k As Long, lr As Long
Dim src As Variant, outp(1 To 35, 1 To 35) As Long
lr = Cells(Rows.Count, 1).End(xlUp).Row
src = Range(Cells(2, 2), Cells(lr, 8)).Value
For i = 1 To lr - 1
  For j = 1 To 6
    For k = j + 1 To 7
      outp(src(i, j), src(i, k)) = outp(src(i, j), src(i, k)) + 1
      outp(src(i, k), src(i, j)) = outp(src(i, j), src(i, k))
    Next k
  Next j
Next i
Range("K2").Resize(35, 35).Value = outp
End Sub

You may add 1:35 to verical and horizontal headers of output table manually. and when you add new rows of lottery results, just rerun the macro. It will replace the results.

From the point of view of calculations - triplets will be not much more work, but how would you like to present them? the result will be no sqare (2D) table, but a cube (3D). Of course it is possible to list all triplets in a list (1-D table)
1-2-3 ; count of 1-2-3
1-2-4 ; count of 1-2-4
and so on, but then we shall probably not allow for listing all 6 identical results for
1-2-3
1-3-2
2-1-3
2-3-1
3-1-2
3-2-1
and that makes programming somewhat harder
Hi thank you for you timely reply and help. thanks so much for you time and expertise most of all. I'm not very well versed in Excel or coding, so this was very confusing for me to say the list. However I was able to get it to work. It wasn't elegant at all. lol. Anyway. the later part of your reply I have absolutely no clue what you mean. I think I get the part where you're asking if I want it to list the triplets in just one order or all possible order? I think but the 1-D, 2-D, 3-D I don't understand so I'll ask you to use your best judgement since you're the expert here I will follow whatever directions you suggest. One other question is that the lottery I play has two drums, 1-35 main drum 1-12 bonus drum. 5 numbers are drawn from the main drum and 2 from bonus drum making a total of seven. I don't know if that would make the code too complicated. I had to adjust the code you provided to make it work with only 5 numbers so I just changed the 6 to 5 and it seemed to work. I went over to check the results to see if it was giving accurate readings and it was so I left it. Here is the code I adjusted.

VBA Code:
Sub pairs_frq_table()
Dim i As Long, j As Long, k As Long, lr As Long
Dim src As Variant, outp(1 To 35, 1 To 35) As Long
lr = Cells(Rows.Count, 1).End(xlUp).Row
src = Range(Cells(2, 2), Cells(lr, 6)).Value
For i = 1 To lr - 1
  For j = 1 To 5
    For k = j + 1 To 5
      outp(src(i, j), src(i, k)) = outp(src(i, j), src(i, k)) + 1
      outp(src(i, k), src(i, j)) = outp(src(i, j), src(i, k))
    Next k
  Next j
Next i
Range("K2").Resize(35, 35).Value = outp
End Sub

Thank you very much
 
Upvote 0
Just a brief answer:
1-D, 2-D, 3-D means one dimentional, two dimentional and three dimentional respectively.

In 1-D data is presented that way that each pair (or triplet) is listed in one column and in next column the count of such pair/triplet is presented. (it can be seen as a line with headers on its side).
in 2-D you have (like Excel cell adressing) i headers with both elements of pair (one in horizontal header second in vertical) and on crossing of column and row there is a count of such pair. In 3-D the third element of tripled shall be presented in a direction perpendicular to 1st and second, so horizontal, but not left-right, but facing towards us-backward.

As for the changes in a code:
Now it focuses only on the first drum. I shall say that I've not noticed that the numbers could repeat (and they do - it's visible already in first row of your sample data).
So shall these numbers from second drum be also included? They could be and they were in original code, threated the same way as these from main drum. But I could imagine thet headers of the table could read: 1,2,...,34,35,1,2,...,11,12 so whole table would be 47 by 47
 
Last edited:
Upvote 0
Just a brief answer:
1-D, 2-D, 3-D means one dimentional, two dimentional and three dimentional respectively.

In 1-D data is presented that way that each pair (or triplet) is listed in one column and in next column the count of such pair/triplet is presented. (it can be seen as a line with headers on its side).
in 2-D you have (like Excel cell adressing) i headers with both elements of pair (one in horizontal header second in vertical) and on crossing of column and row there is a count of such pair. In 3-D the third element of tripled shall be presented in a direction perpendicular to 1st and second, so horizontal, but not left-right, but facing towards us-backward.

As for the changes in a code:
Now it focuses only on the first drum. I shall say that I've not noticed that the numbers could repeat (and they do - it's visible already in first row of your sample data).
So shall these numbers from second drum be also included? They could be and they were in original code, threated the same way as these from main drum. But I could imagine thet headers of the table could read: 1,2,...,34,35,1,2,...,11,12 so whole table would be 47 by 47

Thank you very much for your help and your time. Thank you
 
Upvote 0

Forum statistics

Threads
1,220,965
Messages
6,157,119
Members
451,398
Latest member
rjsteward

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