Case vs If
Tip 2: Case versus IF Statements
Case statements were introduced in version 3.0 of FileMaker. They perform exactly function as an If statement, however can greatly simplify calculations. Case statements are best used in place of a nested If statement. This is best illustrated by examining two calculations which will return a number in words (in the calculated field Display), based on a numeric entry (in the field Number) Using an If statement: If(Number = 1, "One", If(Number = 2, "Two", If(Number = 3, "Three","")))
Using a Case statement
Case(Number = 1,"One", Number=2, "Two", Number=3,"Three")
FILEMAKER: Nested If Statements Vs Case Statements
If ( test; resultOne; resultTwo )
Thanks Davidanders - clearly the Case() statement wins hands down in terms or being easier to read as the complexity increases.
Is there a performance overhead difference though?
The first link
Afterwards, when I remembered your question, I created a modified script to test an unstored 5-level nested If calculation and compared this with a Case statement with 5 arguments on this 36,500 record loop. I did 5 passes for each test, so, approximately 182,500 records per test. In my results, the Case statement was approximately 4% faster.
Wow, thanks for the input. That clinches it then. I'll change some of our Ifs to Case() statements. Shame sometimes that the technicality of the designs is lost on the Users! Guess they should appreciate it longer term as the database increases and the speed is still there!
I make use of the CASE statement more often than the IF statement. It is easier to add that third condition.