Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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...

share|improve this question

migrated from stackoverflow.com Sep 16 '12 at 20:10

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

1 Answer 1

up vote 2 down vote accepted
=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.

Does this work?

=IF(A2<>0,A2,IF(B2=1,B2,0))
share|improve this answer
    
Thanks Brendan. I actually just got that same exact answer as you posted. Works like a charm. Thanks! –  user1590499 Sep 14 '12 at 20:21
    
Wouldn't this work? =IF(A2=0,B2,A2) –  barry houdini Sep 14 '12 at 23:45

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.