Page 1 of 1

Nested IF Statements

Posted: Tue Aug 02, 2005 5:50 pm
by gtackett
I am looking for a way to test a variable for a particular value and then have the output be some simple text. For example, the following expression works good:

IIF(PCPLUS.subacct="100","Pastoral","Administrative")

However I have twelve tests to do. I could do a nested IIF statement but was wondering if FOXPRO had a better logical function. There was a old CASE function from my Pascal days. I looked thru

http://msdn.microsoft.com/library/defau ... ctions.asp

but couldn't find a quick answer.

Am I stuck with the nested IF statements?

I saw a DO CASE commande but figured that was to complicated for the Custom Reports module. Can I build a CASE statement from within Custom Reports?

Posted: Tue Aug 16, 2005 10:48 am
by Tracy
A case statement cannot be done with in the report. The report variables and texts are limited to 254 characters (If I remember correctly). To maintain some clarity in the nested IIF(), use the Variables available in the report and nest them. Remember variable names in the report are named what you like (var1) and used in the report with an ‘m.’ in front of them (m.var1).

Posted: Tue Aug 16, 2005 10:51 am
by gtackett
Thank you for the response! I hadn't thought of the variables idea - that's a good one.

Posted: Thu Aug 18, 2005 10:01 am
by gtackett
I tried your suggestion. Here is the expression I tried to build:

IIF(subacct=100,"Pastor",IIF(subacct=200,"Admin",IIF(subacct=310,"Wor",
IIF(subacct=400,"Evan",IIF(subacct=500,"Cong",IIF(subacct=610,"Disc",
IIF(subacct=690,"Educ",IIF(subacct=691,"Nur",IIF(subacct=695,"StuMin",
IIF(subacct=696,"Pre",IIF(subacct=700,"Miss","Prop")))))))))))

(I trouble typing all this in so I had to include the carriage returns in this post. These CR's are obviously not in my expression.)

This was too many characters. Any suggestions?

Posted: Thu Aug 18, 2005 10:28 am
by Tracy
I suggested nesting the IIF() with variables, create something like the following variables. (Order does matter, create them in nested order, as shown.)

IIF_Miss
IIF(subacct=700,”Miss”,”Prop”)

IIF_Pre
IIF(subacct=696,”Pre”,m.IIF_Miss)

IIF_StuMin
IIF(subacct=695,”StuMin”,m.IIF_Pre)

If these were the only three variables (you have more), the only variable needed to used in the report field object is m.IIF_StuMin.

Posted: Thu Aug 18, 2005 10:47 am
by gtackett
That is so cool. I will try it out. I guess one downside is that I have to create this for each report. Any way to create global variables instead of just local?

We're never satisfied, are we? :D

Posted: Thu Aug 18, 2005 10:51 am
by Tracy
There is not a way to create global variables at this time. Send a request to the wishlist.