Conditionally flag fields for each group (2 columns) based on top N values

58 views Asked by At

I'm trying to get "First Past the Post" figures, and compare this to the Proportional Representation winners for all election counts. I have all the data in the fields below since 1933, but I can't work out the formula. I might need to extract more data, but I'm hoping not to go there...

Essentially, for each grouping of "Year" and "Constituency", I want the top N of "FirstCount". The top N is the count of the Winner column > 0.

In the example below I want to create a new column called "First Past Post" which would be the same as "Winner" for 2016, but for 2020 the first 3 rows would be 1, and all below that would be 0. The number of "Winners" can be 3,4 or 5 (Count of Winner for Year and Constituency)

Year, Constituency, First Count, Winer
2020, Limerick County, 9228, 1
2020, Limerick County, 8436, 1
2020, Limerick County, 6916, 0
2020, Limerick County, 6021, 1
2020, Limerick County, 5810, 1
2016, Limerick County, 12276, 1
2016, Limerick County, 8479, 1
2016, Limerick County, 8013, 1
2016, Limerick County, 5432, 0
1

There are 1 answers

0
P.b On BEST ANSWER

=COUNTIFS($A$2:$A$10;A2;$B$2:$B$10;B2;$C$2:$C$10;">"&C2)+1

Maybe this is helpful. It lists the ranking of matching data in column A and B. If they don't match it resets the ranking.