Mar 16 2024 05:11 PM - edited Mar 16 2024 05:13 PM
I have this list:
Column A Column B
Austria 10
France 20
Italy 30
China 10
USA 40
I want to sum up all the cells in Column B if in Column A there is a European Country
=SUM(SUMIF(A:A,{"Austria","France","Italy"},B:B))
The result is correctly: 60
Now, however, the list of the European countries is much longer and I do not want to include all of them in the Array, but I want to refer to other cells where I have the list of all European countries.
Is there a way to do it? I think in the Array it is not possible to put a reference to a cell range.
Thanks!!!
Marco
Mar 16 2024 10:48 PM
@MarcoTorinoi Don't use the curly brackets at all... just reference the range containing the list of European countries. For example, if Austria, France and Italy were listed in range D2:D4, the formula would be:
=SUM(SUMIF(A:A, D2:D4, B:B))
Note: with older versions of Excel, you may need to press Ctrl+Shift+Enter when inputting this formula.
Mar 17 2024 02:46 AM - edited Mar 17 2024 02:47 AM
Mar 17 2024 04:26 AM
Solution@MarcoTorinoi Did you see my note about pressing Ctrl+Shift+Enter? If you're not using Excel 2021, Excel for MS365 or Excel for the Web, you'll need to press Ctrl+Shift+Enter when inputting that formula. Alternatively, you can also swap out SUM with SUMPRODUCT without the need for CSE:
=SUMPRODUCT(SUMIF(A:A, D2:D4, B:B))
Here's a couple of screenshots using Excel 2010. Note: the curly brackets are added automatically after pressing Ctrl+Shift+Enter (do NOT type them manually)...
Mar 17 2024 09:00 AM
Check out this formula:
=SUM(FILTER(B2:B6,ISNUMBER(FIND(A2:A6,TEXTJOIN(",",,D2:D4)))))
Mar 17 2024 05:07 PM
Mar 17 2024 05:53 PM - edited Mar 17 2024 05:55 PM
@MarcoTorinoi The performance issues are caused by referencing entire worksheet columns (A:A & B:B), which means SUMIF has to process 1,048,576 rows of data for every use of this formula. Try reducing the range according to the size of your dataset (ie: A1:A1000 & B1:B1000) or format your dataset as a structured Excel table (on the ribbon, go to Insert > Table). When referencing an Excel table, the formula would look something like this:
=SUMPRODUCT(SUMIF(Table1[Country], D2:D4, Table1[Amount]))
The built-in column names of an Excel table are dynamic and will expand automatically as the table expands.
Mar 17 2024 04:26 AM
Solution@MarcoTorinoi Did you see my note about pressing Ctrl+Shift+Enter? If you're not using Excel 2021, Excel for MS365 or Excel for the Web, you'll need to press Ctrl+Shift+Enter when inputting that formula. Alternatively, you can also swap out SUM with SUMPRODUCT without the need for CSE:
=SUMPRODUCT(SUMIF(A:A, D2:D4, B:B))
Here's a couple of screenshots using Excel 2010. Note: the curly brackets are added automatically after pressing Ctrl+Shift+Enter (do NOT type them manually)...