5 Replies Latest reply: May 15, 2014 10:07 AM by Data Kruncher

# Can we do nested if?????

Any reason why this nested if statement didn't work

If(Inst=1,"01",if(Inst=2,"02",if(Inst=4,"04"))) and I tried this if(Inst=1,01,if(Inst=2,02,if(inst=4,04)))

• ###### Can we do nested if?????

You must supply a value or an operation for both the True condition and[/I] the False condition.

If(Inst=1,"01",if(Inst=2,"02",if(Inst=4,"04","Another Value")))[/CODE]

• ###### Can we do nested if?????

Thanks Works perfectly:)

• ###### Can we do nested if?????

Hello Set_Shot,

Nested If statements are fine for 3 or 4 conditions, but can get a bit unwieldy when you have more possible input options. Monarch lets you define a type of calculated field called an "internal lookup" field which can help.

You can ask Monarch to read in all the input values of the field in your data, and then select the output values for each of these, as well as defining options for empty, null and other values.

It's much easier to see what's going on, and to document your model, using these than using a nested If with dozens of clauses...

Best wishes,

Olly

• ###### Can we do nested if?????

FYI... In your case you could also get away with using appended If()s. This:

If(Inst=1,"01","")IF(Inst=2,"02","")IF(Inst=4,"04","Another Value")

/code

..would be perfectly acceptable.

But, to be perfectly honest, you'd be better off following Olly's suggestion of using a Lookup.

• ###### Can we do nested if?????

Or we might be able to do away with nested Ifs and lookups completely by generating the same end result with:

Right("00"+trim(str(MyValue)),2)[/CODE]