Can't use SUM(IF()) for multiple condition lookup if target is text (XL2003)

elihubogan

New Member
Joined
May 26, 2011
Messages
3
In context, imagine you have a table with Columns (A) City, (B) State, and (C) Population. I'm familiar with arrays like this to return the population for each city/state combination:

{=SUM(IF((CityA=$A$Column)*(StateB=$B$Column),$C$Column,"Error"))}

When Columns A and B are unique combinations, I've used this as a multiple condition lookup as an alternative to vlookup.

However, when I try to run it where Column C's values are text, not numbers (say the name of the Mayor), obviously the SUM(IF()) won't work. I tried the same function like this:

{=IF((CityA=$A$Column)*(StateB=$B$Column),$C$Column,"Error")}

This is also a fail. Any ideas? I know there are workarounds (create an ID="CityA"&"CityB" then just do =VLOOKUP(ID,$ID$Column,2,false), but I don't like not having a more elegant solution.
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
Hello elihubogan, welcome to MrExcel, try LOOKUP like this

=LOOKUP(2,1/(CityA=$A$Column)/(StateB=$B$Column),$C$Column)

or an array formula

=INDEX($C$Column,MATCH(1,(CityA=$A$Column)*(StateB=$B$Column),0))

confirmed with CTRL+SHIFT+ENTER

If there are multiple matches then LOOKUP finds the last, INDEX/MATCH the first......
 
Upvote 0
Thanks for the quick reply! I tried plugging in your formulas, and the index array worked great. I think I lost something in translation with the Lookup formula though (probably b/c I made up that silly notation).

if my sum(if) looks like this:

=SUM(IF(($A$6:$A$10=F6)*($B$6:$B$10=G6),$C$6:$C$10,"error"))

The following throws a formula error b/c I think there's division by 0:

=LOOKUP(2,1/F6=$A$6:$A$10)/(G6=$B$6:$B$10),$C$6:$C$10)

So I tried this, which returned values, just not the right ones:

=LOOKUP(2,(1*(F6=$A$6:$A$10)+1*(G6=$B$6:$B$10)),$C$6:$C$10)

Could you clarify? Thanks so much for your help, the index solution is indeed elegant!
 
Upvote 0
Thanks for the quick reply! I tried plugging in your formulas, and the index array worked great. I think I lost something in translation with the Lookup formula though (probably b/c I made up that silly notation).

if my sum(if) looks like this:

=SUM(IF(($A$6:$A$10=F6)*($B$6:$B$10=G6),$C$6:$C$10,"error"))

The following throws a formula error b/c I think there's division by 0:

=LOOKUP(2,1/F6=$A$6:$A$10)/(G6=$B$6:$B$10),$C$6:$C$10)

So I tried this, which returned values, just not the right ones:

=LOOKUP(2,(1*(F6=$A$6:$A$10)+1*(G6=$B$6:$B$10)),$C$6:$C$10)

Could you clarify? Thanks so much for your help, the index solution is indeed elegant!
The highlighted formula is missing a ( immediately after the 1/.

=LOOKUP(2,1/(F6=$A$6:$A$10)/(G6=$B$6:$B$10),$C$6:$C$10)
 
Upvote 0

Forum statistics

Threads
1,223,898
Messages
6,175,274
Members
452,628
Latest member
dd2

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top