简体   繁体   中英

Comparing one table column against another column using SUMPRODUCT

I am looking into writing a formula that counts how many entries in a column Data[Country] match a list determined in a separate table column Included[Countries] .

I have tried using the SUMPRODUCT function as below:

= SUMPRODUCT(--(Data[Country]=Included[Countries]))

but this returns an error. If I replace Included[Countries] by an array of the constituents, eg =SUMPRODUCT(--(Data[Country]={"EN","DE"})) , this works, however I want to avoid harcoded values.

I have also tried COUNTIFS(Data[Country], Included[Countries]) but this has not worked.

Any ideas please?

=SUMPRODUCT(--(Data[Country]=Included[Countries])) does not work as SUMPRODUCT expects the two ranges to be the same size at it will iterate both row by row. If they are different sizes it will return an error.

=SUMPRODUCT(--(Data[Country]=Included[Countries])) works because you are using an array and not a range.

=COUNTIFS(Data[Country], Included[Countries]) does not iterate on its own and thus will only return the first cell count.

To get it to iterate use COUNTIFS() inside SUMPRODUCT():

=SUMPRODUCT(COUNTIFS(Data[Country], Included[Countries]))

So, you were close to the solution, just needed to understand how to combine the two approaches.

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