FM Function of the Week: Sign

Sign is a nice example of a compact, efficient function that can really cut down the length of certain calculations. Its utility is simply this: check a number and report whether it’s negative, zero, or positive.sign function examples

Sign accepts just one parameter which must either be a number or an expression that resolves to a number. If that parameter is a negative value of any amount, Sign returns -1. Similarly, if the parameter is any positive number, Sign returns a (positive) 1. Zero begets zero. Fundamentally it’s like asking FileMaker “where does this value fall on the number line?”

If you’re thinking “that’s a pretty easy Case function to write” you’d be correct. But using Sign will benefit the efficiency, compactness, and readability of your code. In the comparison below, using Case requires nearly four times the characters and, when formatted for readability, five lines instead of one.comparison of Sign and Case functions

How about a real-world example? We can use Sign in combination with our friend the Choose function to generate a message to appear on an invoice or statement. This calc will show an appropriate message whether the customer owes you money, you owe the customer, or the two parties are even.

calculation that selects a message based on the result of Sign

This entry was posted in FileMaker 13, Function of the Week. Bookmark the permalink.