Calculated fields and entering formulas |
GS-Base uses formulas in the following procedures/functions:
To enter/edit a formula
Formulas available in GS-Base are similar to those used in spreadsheets with a few exceptions:
For example:
to sum up two fields 'subtotal' and 'tax', use the following formula:
=subtotal + tax
to merge two fields 'name' and 'country', use the following formula:
=name & ", " & country
and to obtain a period string representing the difference between two given dates:
=dateDiff("2011-01-01", "2011-12-31") (which returns "P364D")
to find the current age for birth dates stored in the "date" field:
=year(today()) - year(date) - if(month(date) < month(today()), 0, if(month(date) > month(today()), 1, day(date) >= day(today())))
Note: If the "date" field is not a valid GS-Base date field (that is, a text field containing generic date/time YYYY-MM-DD strings that can be formatted to be displayed in the desirable local format), the above "date" argument should be replaced by dateValue(date).
A few other examples:
=Unit_Price*Qty
="abc"
=1 + 2
="a" & 'b' & 3
=fv(0.75%, 36, -500, -5500, 0)
=LProg({2,2;1,2;4,0}, {1;1;1}, {14;8;16}, {2; 4},0,,)
=sum(field1, field2, field3, sum(field4, field5, field6))
Numbers and dates used as arguments cannot be formatted. For example, the following expressions are incorrect:
=$1,000.00 + 1
=dateDiff("6/3/11", "8/9/2011")
unless the description specifically states that parameters are arbitrary text strings to be converted to a specific type, like:
=value("$1,000.00") + 1
=dateDiff(dateValue("6/3/11"), dateValue("8/9/2011"))
Text strings should be delimited either by single or double quotation marks.
Formulas should not contain circular field references.
To browse all available formula categories and examples, please see the Field Setup dialog box or the Search dialog box.
Note: Square brackets [,] in parameter lists denote parameters that are optional and can be omitted. For example:
LProg(A, s, b, c, vector, [epsilon], [m])
However, you still have to use the corresponding parameter list separators, that is:
LProg(A, s, b, c, vector,,)
If your current Windows regional settings define commas as decimal separators, use semicolons (;) to separate function arguments or - if you prefer to use system independent (US) settings - select the generic locales via the Settings > Locales > Generic command.
Available operators:
Operator | Operation | Comments | Precedence |
= | Equal | Compares numbers or text strings (the comparison is not case-sensitive). Example: A1=4 , B2="abc" | 6 |
< | Less than | Compares numbers or text strings (the comparison is not case-sensitive). Example: A1<4 , B2<"abc" | 6 |
> | Greater than | Compares numbers or text strings (the comparison is not case-sensitive). Example: A1>4 , B2>"abc" | 6 |
<= | Less than or equal | Compares numbers or text strings (the comparison is not case-sensitive). Example: A1<=4 , B2<="abc" | 6 |
>= | Greater than or equal | Compares numbers or text strings (the comparison is not case-sensitive). Example: A1>=4 , B2>="abc" | 6 |
<> | Not equal | Compares numbers or text strings (the comparison is not case-sensitive). Example: A1<>4 , B2<>"abc" | 6 |
+ | Addition | Adds numbers. | 5 |
- | Subtraction | 5 | |
& | String concatenation | Merges text strings. Example: A1 & "abc" , "a" & "b" | 5 |
* | Multiplication | Multiplies numbers. | 4 |
/ | Division | Divides numbers. | 4 |
^ | To the power of | Calculates the power of. | 3 |
- | Negative | Example: -A1 | 2 |
% | Percent | Specifies a number entered as a percentage. Example: 12% | 1 |