Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using spreadsheet to make a pairwise comparison matrix

I want to use a spreadsheet to take a column of rankings and turning into a pairwise matrix. Suppose I had a column like so:

Candidate Ranking
A 1
B 5
C 3
D 2
E 4

I want to create a 5x5 matrix where each cell displays a 1 if the row candidate beats the column candidate, and a 0 otherwise, like so:

Pairwise Matrix in Sheets

(I don't know how to make a table of more than 2 columns here, so I used an image.)

I was able to make this table by manually making the first cell of each column individually, using an if statement, and dragging down, but I'd like to make a single formula that can do the whole table at once.

like image 844
James Cleveland-Tran Avatar asked May 04 '26 08:05

James Cleveland-Tran


2 Answers

Row Beats Column

Readable (D1:I6,K1:P6)

=LET(t,A2:A6,c,B2:B6,title,"T",
    h,HSTACK(title,TOROW(t)),
    r,TOROW(c),
    d,IF(r=c,"",IF(r>c,1,0)),
    VSTACK(h,HSTACK(t,d)))

Short (D1:I6,K1:P6)

=LET(t,A2:A6,c,B2:B6,title,"T",
    r,TOROW(c),
    VSTACK(HSTACK(title,TOROW(t)),
        HSTACK(t,IF(r=c,"",IF(r>c,1,0)))))

Matrix Only (E2:I6,L2:P6)

=LET(c,B2:B6,
    r,TOROW(c),
    IF(r=c,"",IF(r>c,1,0)))

Screenshot of the Data and the Result

Ingredients

K1: =HSTACK("T",TOROW(A2:A6))
K2: =A2:A6
L2: =IF(TOROW(B2:B6)=B2:B6,"",IF(TOROW(B2:B6)>B2:B6,1,0))
like image 59
VBasic2008 Avatar answered May 07 '26 11:05

VBasic2008


The following formula will do what you want:

=IF(G$1<>$F2,IF(INDEX($B$2:$B$6,MATCH($F2,$A$2:$A$6,0))<INDEX($B$2:$B$6,MATCH(G$1,$A$2:$A$6,0)),1,0),"-")

example:

enter image description here

like image 31
cybernetic.nomad Avatar answered May 07 '26 10:05

cybernetic.nomad



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!