|
Logic Functions
Logic functions allow you to perform a test on your record, and return different results from the formula based on whether the test passed or failed. The simplest example is with the if function, which returns one value if the test is true, and another if it's false. For example, a calculated percentage field called Discount could have a formula of if(total sale > 1000, 10%, 0)
which should be interpreted as meaning, "If the total sale is more than $1000, then use a 10% discount, otherwise use zero discount." Tests can also be nested: if(total sale > 5000, 20%, if(total sale > 1000, 10%, 0))
Here the "otherwise" value of the first if(...) is another if(...) function. The formula means, "If the total sale is greater than $5000, then use 20%, otherwise if it's greater than $1000, use 10%, otherwise use zero." Comparisons can be made with text fields: if(sex = "Male", "Mr.", "Ms.")
To compare a text value with many different choices, use the map function instead of nesting a bunch of if(...) functions. A Full State Name field could have a formula of map(state abbreviation, "CA", "California", "NY", "New York", "DC", "Washington D.C.")
This formula will examine the value of the State Abbreivation field, and return California if it matches CA, otherwise New York if it matches NY, and so on. You can put in a final value that will be returned in none of the values match: map(state abbreviation, "CA", "California", "NY", "New York", "DC", "Washington D.C.", "fly-over country")
You can also test multiple conditions using the function and(test1, test2, ...), which is true only if all of the tests in it are true, or or(test1, test2, ...), which is true if any of the tests in it are true. For example, to give a discount to both large purchases and good clients, we could use if( or(total sale > 5000, client type = "best"), 20%, 0%)
Note that the = test compares values as if they were text. Therefore, 10.0 and 10 are not considered equal by the = operator. This is usually not a problem in numeric calculations, because TrackVia represents all numbers internally in a consistent way. (That is, it will use 10 for calculations instead of 10.0, even if your display options in a particular view are set to show 10.0, or $10.00.) However, it can be a problem if your numeric values are coming from a text field, like a short answer or drop-down field. If you want to force TrackVia to test the equality of two values as if they were numbers, you can use the == operator, as in if(my dropdown field == 10, "yes", "no")
If you use = with text fields, the comparison is case sensitive, so Bob does not equal bob. To make a case-insensitive test between fields A and B, you can convert them both to lowercase first, like lower(A) = lower(B). Finally, for information about the parentlookup function, which allows you to pull data from records linked by a link to parent record field into a child record, see the Relational Fields article. TrackVia has many different functions for testing your data and performing complex logic. For help setting up TrackVia to solve your particular problem, please feel free to contact us! Built-in functions. TrackVia's built-in logic and comparison functions are shown below. The quantities in parentheses are inputs that the the function requires. In your formulas, these should be database field names, numbers, text inside quotation marks, etc.
|