Thursday, May 24, 2007

How to determine the winner of a multiple candidate field with Excel



I just struggled for ten minutes to show Andrew Wolfson how to compute an average in Excel, so I'm not optimistic many will make use of the following, but here goes.


Say there was just an election for governor and you have county-by-county vote totals for the six Democratic candidates. How do you determine the winner in each of the 120 counties, while also taking into account the possibility there could be ties?


Here's one solution, cadged from some online searches and scraps of old postings on NICAR-L. If anyone identifies a flaw in my work, please let me know. The formula looks like this:


=IF(COUNTIF(C2:H2,MAX(C2:H2))>1,"Tie",INDEX($C$1:$H$1,1,MATCH(MAX(C2:H2),C2:H2,0)))



The top row of the spreadsheet is arranged this way:


County Precincts Beshear Galbraith Henry Hensley Lunsford Richards Winner


Each subsequent row gives the vote totals for each candidate, in columns C to H. The formula, which you copy down each row in the winner column, looks in that row and if there is more than one largest number, as determined by the MAX() function, writes "Tie." Otherwise it takes the cell with the largest number, then, using a combination of the INDEX() and MATCH() functions, looks for the corresponding header of that column and writes that in the winner column.

I hope that's clear. If you have any questions about the details of how these functions work, consult Excel's help files or Wolfson.



1 comments:

Gregory Korte said...

As someone who has covered more than his fair share of 26-candidate field races for Cincinnati City Council, all I can say is: Thank you, thank you, thank you....