简体   繁体   中英

RANK IF formula on Google Sheets with SUM

I am trying to create a ranking of summed numbers out of a database. The Database has a list of individual offices of companies in certain countries (numbered 1-10). In some cases, the same company is in multiple countries. Countries are listed in Column A; Companies are in column B; Offices are in column C.

Each individual office has a score. Office scores are in column D of the database.

I would like to create a rank of companies based on the company's total score per country. The company's total score per country is the sum of scores of all offices of the same company in the same country.

In order to build such a ranking one would have to:

1 - Get the company's total score per country. I have done this using a SUMIFS function. This is the function I've used to calculate this score: =SUMIFS($D$2:$D, $A$2:$A, $A2, $B$2:$B, $B2) . This is calculated in column E of the database.

2- Rank it against the list of other companies' total score per country only for those companies that are in the same country.

I am having trouble defining the range for the RANK and have learnt that this is not possible to do using a function like this. The range against which to rank the value calculated on step 1 needs to be a conditional sum as well - the sum of all scores in the country of the office we are ranking. How can this be done?

After doing some research, I have tried solutions involving SUMPRODUCT and COUNTIFS but have failed to achieved the desired result. How can I do this?

I have created a sample shee t here that might help to understand the problem here .

Thank you

If you want to be able to rank them, you 1st have to find and sort all the values for the current country.
Like @|'-'|, I used a query:

=QUERY($A$2:$E;"select E WHERE A="&A2&" ORDER BY E DESC")

Since the same number can apear twice, you want to add a UNIQUE around that. Be carefull, if 2 companies have the same score, they'll have the same rank.

=UNIQUE(QUERY($A$2:$E;"select E WHERE A="&A2&" ORDER BY E DESC"))

This will return the range, sorted from the greatest to the least. Now you simply have to get the index of your current score with the match function.

=MATCH(E2;UNIQUE(QUERY($A$2:$E;"select E WHERE A="&A2&" ORDER BY E DESC"));0)

This may help:

=query(A:D,"Select A,B,sum(D) group by A,B order by A,sum(D) desc")

This doesn't RANK,but SORTs the SUM in the descending order.

Rank the selection against a filtered range. Example:

=Rank(C2,Filter(C$2:$C$71,F$2:$F$71=F2),1)

This would rank the value in c2 only if the values in f2:f72 are equal to the value in f2 (this rankes the lowest values with the lowest rank

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM