Solved

multiple ifs in a calculated field

Posted on 2006-07-14
4
866 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
ID: 17113024
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
ID: 17113417
thank you bill. i like the case() statement. never knew how to use it.
0
 
LVL 28

Expert Comment

by:lesouef
ID: 17113436
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
ID: 17113438
obviously, we were typing at the same time!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Problem: You have a hosted FileMaker database and users are tired of having to use Open Remote or Open Recent to access the database. They say, "can't you just give us something to double-click on rather than have to go through those dialogs?" An…
A company’s greatest vulnerability is their email. CEO fraud, ransomware and spear phishing attacks are the no1 threat to a company’s security. Cybercrime is responsible for the largest loss of money to companies today with losses projected to r…
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

919 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

12 Experts available now in Live!

Get 1:1 Help Now