# Nested IF's in Excel

I have two columns with the following possibilities (0 for first column, and then 0 or 1 for second column; or a string for first column, and a 0 or 1 for second column).

``````name,flag
0,0
david,0
0,1
sammy,1
``````

How would I create a third column that looks like the following:

``````name+flag
0
david
1
sammy
``````

Basically, if there are 2 0's in the two columns in a row, put a 0 in the new column. if there is a string in the first column in the row, no matter what the second column in the row says, put the string in the new column. and if there is a 0 in the first column and a 1 on the second column, put a 1 in the third column.

Can I do this best with nested-if's? I tried something like

``````name, flag, name+flag
0,0,=IF(A2<>0,A2,IF(B2=1,B2,0),0)
``````

But it didn't seem to work for me...

-

## migrated from stackoverflow.comSep 16 '12 at 20:10

This question came from our site for professional and enthusiast programmers.

``````=IF(A2<>0,A2,IF(B2=1,B2,0),0)
Your outer `IF` has 4 arguments, but the inner one has 3. The documentation suggests that 3 is the correct number.
``````=IF(A2<>0,A2,IF(B2=1,B2,0))
Wouldn't this work? `=IF(A2=0,B2,A2)` – barry houdini Sep 14 '12 at 23:45