Solved

multiple ifs in a calculated field

Posted on 2006-07-14
4
865 Views
Last Modified: 2010-04-27
how can i create multiple if statements in a calculated field?
i dont see an else or else if statement in list of commands

i want to do three tests and fill the field contents with 1 of the three possible descriptions

if field 1 > "" then "field one is occupied"
   else
if field 2 > "" then "field two is occupied"
   else
                           "both field are empty"
0
Comment
Question by:kauakea
  • 2
4 Comments
 
LVL 19

Accepted Solution

by:
billmercer earned 500 total points
Comment Utility
The else in a calculated field isn't explicit, it's built into the If() function itself, like this:

  if( Something is true ;  SomeValue ;  SomeOtherValue )

To make it easier to understand this logic, you can separate the calculation into multiple lines, so it looks more like a script or program.
   if( Something is true ;   // IF
          SomeValue ;        // THEN
          SomeOtherValue  // ELSE
     )                             //END IF

So to do what you want, you could use a second nested if() inside the first one, where one of the results from the if() is another if(). Something like this:

  if ( field1 > ""; "Field1 Occupied"; if ( field2 > "" ; "Field2 Occupied"; "Both fields empty" ) )

If you have multiple tests you want to make, you can use the Case() function instead, which acts like a series of if-else statements, like this:

case ( field1 > "" ; "Field1 is occupied";  // if
         field2 > "" ; "Field2 is occupied";  // else if
         field3 > "" ; "Field3 is occupied";  // else if
         "All three fields are empty"         // else        
)

Another function that is very useful when trying to create complex calculations is the LET() function, which allows you to assign values to local variables that are used only within a calculation. This can be very handy when creating complicated calculations

If you have FileMaker Advanced, you can use the custom functions feature to create recursive functions, which will allow you to use primitive looping in a calculation as well, but aside from this, there really isn't any sort of "flow control" in a Filemaker calculation. It's all just one big expression.

0
 

Author Comment

by:kauakea
Comment Utility
thank you bill. i like the case() statement. never knew how to use it.
0
 
LVL 28

Expert Comment

by:lesouef
Comment Utility
I'll vote for "case" in yr case. Nested ifs are hard to read back a few months later!.
Also, be care in yr example, the case where field 1 and 2 would be empty is handled as both busy.
In Bill's example, if several fields are busy, it will be reported as only the first is busy as the case function exits when the 1st condition is met.
so according to me, this be done as a serie of concatenated tests:

if (field1>"" ; "field1 is occupied¶" ; "" ) &
if (field2>"" ; "field2 is occupied¶" ; "" ) &
if (field3>"" ; "field3 is occupied¶" ; "" ) &
if (field1 =""  And field2="" And field3=""; "empty¶")

and uncheck the "no calculation if all fields are empty" flag at the bottom left of the calculation window to get "empty" to be calculated as well.
0
 
LVL 28

Expert Comment

by:lesouef
Comment Utility
obviously, we were typing at the same time!
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Suggested Solutions

Pop up windows can be a useful feature of any Filemaker database.  Though best used sparingly, they can be employed in a multitude of different ways, for example;  as a splash screen at login, during scripted processes to control user input, as pick…
Conversion Steps for merging and consolidating separate Filemaker files The following is a step-by-step guide for the process of consolidating two or more FileMaker files (version 7 and later) into a single file with multiple tables. Sometimes th…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now