Field type - formula

The formula field allows you to enter formulas to manipulate text, numbers, and dates stored in fields in a tab and use them to derive a value that should display in the new field. Builders will use the formula editor to enter the function (a piece of instruction designed to calculate specific values) that will return the desired information in the field. Use formulas to:

  • Do basic math functions using existing fields in the tab
  • Derive a date or, do date-based calculations
  • Concatenate data together
  • Show a value in a field when certain conditions are met
  • And much more

Formula fields are not directly editable and will auto-calculate based on the function instruction of the formula. They display with a light blue background: Image. The value from a function field can be downloaded, filtered, and looked up via integration using the Block's API.

This article covers:

Fundamentals

Many formulas will be built by looking up information in another field on the tab. The field name will be referenced in the formula editor section of the function field using encased curly brackets: {field name} Any time you want to evaluate numbers or text to then output a specific set of information, you will use the CASE function. Below is an example of illustrating how a CASE formula is constructed:

Example formulas:

Example 1:

CASE

WHEN {Assembly Cost} > 1000 THEN 'Large'

WHEN {Assembly Cost} BETWEEN 500 AND 999 THEN 'Medium'

WHEN {Assembly Cost} BETWEEN 0 AND 499 THEN 'Small'

ELSE 'Unknown'

END

 

Result:

Given that the tab has a field named Price. When this field has a value under 1000 then show the text Large, if it's between 500 and 999 then show the text Medium, and when the process is between 0 and 499, show the text Small, otherwise, show the value of Unknown.

 

Example 2:

CASE
WHEN {Job Code}='MFAS1' then TO_CHAR({Hourly Pay Rate}*1.35,'L999D99')
WHEN {Job Code}='FAAC1' then TO_CHAR({Hourly Pay Rate}*2,'L999D99')
ELSE 'enter a valid code'
end

 

Result:

Given that there are two fields in the tab, Job Code and Hourly pay rate (which is a number). If the job code is MFAS1, then multiply the hourly pay rate times 1.35, then convert it to a text string and output it in the format that is like $999.99. If the job code is FAAC1, then multiply it times 2, then convert it to a text string that is output in the format that is like $999.99. For all other job codes found including null values, output the string: enter a valid job code.

 

Example 3:

TO CHAR ({Social Security Number}, '000 - 000 - 0000')

Given that there is a number field in the tab called Social Security Number, format the social security number as prescribed. In this example, the social security number stored in the number field (hence losing it's leading 0) as 89889989 would be output as a string that adds back the leading 0, like this: 089 - 88 - 9989.

 

🔔 Formulas can not mix the output of numbers and strings. This means, if you put a TO_CHAR function on one line of your formula, every scenario included in your formula must result in a string output.

 

🔔 If you format a string using TO_CHAR to an output that is incompatible with the result, the expected format for the field will display instead. Using example 2, if the resulting calculation was greater than $999.99 for the first two WHEN statements, then instead of showing the calculation it would show: $###.##

 

CASE statement operators

When building a CASE statement, the following operators are available and can be used when evaluating text strings, numbers and or dates.

Operator Description Where applicable

CASE

Used to set up if/then scenarios - in a case where this is true, do this, otherwise do that. string, number, date
WHEN....ELSE Use to define when (WHEN) an event should happen what to do and otherwise what to do (ELSE) string, number, date
AND Users when all function elements must be true string, number, date

OR

Used when only one of the specified function elements must be true string, number, date
NOT Used when the function element must not be present string, number, date
= Equal to - can be used with any type of function string, number, date
> Greater than number, date
< Less than number, date
>= Greater than or equal to number, date
<= Less than or equal to number, date
BETWEEN

Between two numbers

Syntax: BETWEEN Number AND Number

number, date
NOT BETWEEN

Not between two numbers

NOT BETWEEN Number AND Number

number, date
IS NULL When a field has no value specified string, number, date
IS NOT NULL When a field has some value specified string, number, date
LIKE

Where a field has a value similar to the value specified example where the % can be used to specify a wildcard ending or a _ can be used to specify a single wildcard character. eg: Like 'b*' would return anything that starts with b. Where 'b_' would return anything that starts with b and is followed by only a single character.

Example: Given boo, LIKE 'b*' is TRUE but 'b_' would return false because boo is 3, not 2, characters.

string
NOT LIKE Where a field does not have a value similar to the value specified following the same syntax scenario as used for LIKE (see above) string

 

CAST

The CAST function converts one datatype into another datatype. For example, if a field is a string, but you'd like to use it in a calculation, you will want to use this function. This will convert the value into a number that can be calculated.

The syntax format for this function is CAST({field to convert} as datatype). In the syntax examples below, you see a number in quotes at the start '1234'. This string can be replaced with a field from the tab in curly brackets. For example the second format option below (which would be used for SSN formatting where you have a field of the name SSN in the tab. This would be written as: CAST({Market Max} as numeric).

For the cast function to work, the data in the expression being evaluated must consist of the datatype specified. For example, you can not use CAST to convert the value A into the value 1. You can convert the string value of 1 into a numeric value of 1, so that it can be used for calculations.

 

🔔 It's important to note that any lookup fields that look up numeric fields are technically strings in GraceBlocks; they will need the CAST function applied to use this number in a formula.

 

There are two syntax options for this function:

Option 1: CAST (expression AS target_datatype ) --- example: CAST({Max salary} as numeric)

Option 2: expression :: target datatype --- example: '15 minute'::interval

 

Target datatype

 

Description Syntax example Possible result
numeric

Will convert to a number. Syntax example: CAST({Field to convert} as numeric)

 

CAST({Market Max} as numeric)

85000

 

🔔 To then format this number as $85,000.87 be sure to set the numeric properties for the field.

INTEGER

Will convert into an integer

CAST('100' as integer)

100

DATE

Will convert into a date field - date strings that can be converted include:

March 1, 2025

Mar 1, 2025

01-Mar-2025

01-MAR-2025

01/03/2025

1/3/25

(when a 2 digit year is used, values 70-99 produce 19 for the first two digits of the year, like 1979, but 69 and lower will produce 20 for the first two digits of the year, like 2069.)

 

'March 1, 2025' :: DATE

03-Mar-2025

 

Specify the format of the date using the date properties for the field.

BOOLEAN

Will convert into a boolean value (true or false)

possible values to be converted: True, TRUE, T, t, FALSE, False, F, f

Cast ('T' AS BOOLEAN)

true

text

Will convert into a text string

Cast ('1' as text)

1

🔔 if you want to contact a number with other string values you will need to cast the number as a string in the formula for it to work.

 

TO_CHAR

The TO_CHAR function converts a date or number value into a text string. The syntax format for this function is TO_CHAR({field to convert}, 'format to apply'). In the syntax examples below, you see a number in quotes at the start '1234'. This string can be replaced with a field from the tab in curly brackets. For example the second format option below (which would be used for SSN formatting where you have a field of the name SSN in the tab. This would be written as: TO_CHAR({SSN}, '000-000-0000')

Format (numbers) Description Syntax example Possible result
9 Numeric value with the specified number of digits TO_CHAR('89559999','999-99-9999') 89-55-9999
0 Numeric value with leading zeros TO_CHAR('89559999', '000-00-0000') 089-55-9999
D decimal point TO_CHAR('40', '9999D99') 40.00
, (comma) group (thousand) separator TO_CHAR('1009001', '999,999,999' 1,009,001
PR Negative value in angle brackets. TO_CHAR('-189729',('999999PR') <189729>
S Sign (eg: + or -) anchored to a number. The "S" can be placed before or after the number definition in specifying the syntax.

TO_CHAR('-189729',('S999999')

TO_CHAR('189729',('999999S')

 

-189729

189729+

L Currency symbol TO_CHAR('45'), 'L999' $45
G Group separator ( format a number with the appropriate number of significant digits)

TO_CHAR('1234.56789', 'G9990.00')

 

1234.57
RN Roman numeral that ranges from 1 to 3999 TO_CHAR('50', 'RN') L

 

TO CHAR DATE FORMATS

In all examples, the date used as the {Updated on} value is 24-May-2023 11:41:12 am EST.

Pattern (dates) Description Syntax example Possible result
Y,YYY year in 4 digits with comma TO_CHAR({Updated on}, 'Y,YYY') 2,023
YYYY year in 4 digits TO_CHAR({Updated on}, 'YYYY') 2023
YYY last 3 digits of year TO_CHAR({Updated on}, 'YYY') 023
YY last 2 digits of year TO_CHAR({Updated on}, 'YY') 23
Y The last digit of year TO_CHAR({Updated on}, 'Y') 3
IYYY ISO 8601 week-numbering year (4 or more digits) TO_CHAR({Updated on}, 'IYYY') 2023
IYY Last 3 digits of ISO 8601 week-numbering year TO_CHAR({Updated on}, 'IYY') 023
IY Last 2 digits of ISO 8601 week-numbering year TO_CHAR({Updated on}, 'IY') 23
I Last digit of ISO 8601 week-numbering year TO_CHAR({Updated on}, 'I') 3
BC, bc, AD or ad Era indicator without periods TO_CHAR({Updated on}, 'BC') AD
B.C., b.c., A.D. ora.d. Era indicator with periods TO_CHAR({Updated on}, 'b.c.') a.d.
MONTH English month name in uppercase TO_CHAR({Updated on}, 'MONTH')

MAY

had our sample date been in December the value would have been: DECEMBER.

Month Full capitalized English month name TO_CHAR({Updated on}, 'Month')

May

had our sample date been in December the value would have been: December

month Full lowercase English month name TO_CHAR({Updated on}, 'month')

may

Had the sample date been in December the value would have been: december

MON Abbreviated uppercase month name e.g., JAN, FEB, etc. TO_CHAR({Updated on}, 'MON') MAY
Mon Abbreviated capitalized month name e.g, Jan, Feb,  etc. TO_CHAR({Updated on}, 'Mon') May
mon Abbreviated lowercase month name e.g., jan, feb, etc. TO_CHAR({Updated on}, 'mon') may
MM month number from 01 to 12 TO_CHAR({Updated on}, 'MM') 05
DAY Full uppercase day name TO_CHAR({Updated on}, 'DAY') WEDNESDAY
Day Full capitalized day name TO_CHAR({Updated on}, 'Day') Wednesday
day Full lowercase day name TO_CHAR({Updated on}, 'day') wednesday
DY Abbreviated uppercase day name TO_CHAR({Updated on}, 'DY') WED.
Dy Abbreviated capitalized day name TO_CHAR({Updated on}, 'Dy') Wed.
dy Abbreviated lowercase day name TO_CHAR({Updated on}, 'dy') wed
DDD Day of year (001-366) TO_CHAR({Updated on}, 'DDD') 144
IDDD Day of ISO 8601 week-numbering year (001-371; day 1 of the year is Monday of the first ISO week) TO_CHAR({Updated on}, 'IDDD') 143
DD Day of month (01-31) TO_CHAR({Updated on}, 'DD') 24
D Day of the week, Sunday (1) to Saturday (7) TO_CHAR({Updated on}, 'D') 4
ID ISO 8601 day of the week, Monday (1) to Sunday (7) TO_CHAR({Updated on}, 'ID') 3
W Week of month (1-5) (the first week starts on the first day of the month) TO_CHAR({Updated on}, 'W') 4
WW Week number of year (1-53) (the first week starts on the first day of the year) TO_CHAR({Updated on}, 'WW') 21
IW Week number of ISO 8601 week-numbering year (01-53; the first Thursday of the year is in week 1) TO_CHAR({Updated on}, 'IW') 21
CC Century e.g, 21, 22, etc. TO_CHAR({Updated on}, 'CC') 21
J Julian Day (integer days since November 24, 4714 BC at midnight UTC) TO_CHAR({Updated on}, 'J') 2460089
RM Month in upper case Roman numerals (I-XII; > TO_CHAR({Updated on}, 'RM') V
rm Month in lowercase Roman numerals (i-xii; > TO_CHAR({Updated on}, 'rm') v
HH or HH12 Hour of day (0-12) TO_CHAR({Updated on}, 'HH') 11
HH24 Hour of day (0-23) TO_CHAR({Updated on}, 'HH24') 11
MI Minute (0-59) TO_CHAR({Updated on}, 'MI') 41
SS Second (0-59) TO_CHAR({Updated on}, 'SS') 12
MS Millisecond (000-999) TO_CHAR({Updated on}, 'MS') 453
US Microsecond (000000-999999) TO_CHAR({Updated on}, 'US') 453000
SSSS Seconds past midnight (0-86399) TO_CHAR({Updated on}, 'SSSS') 56467
AM, am, PM or pm Meridiem indicator (without periods) TO_CHAR({Updated on}, 'PM') AM
A.M., a.m., P.M. or p.m. Meridiem indicator (with periods) TO_CHAR({Updated on}, 'p.m.') a.m.
Q Quarter TO_CHAR({Updatedon}, 'Q') 2

Math Operators

Where any number field, or lookup that outputs a number value, residing in the tab where the formula is being added, can be inserted as a number using the format {fieldname}. For example, {Salary} + {Annual Bonus}.  The result of this formula, where these two fields in a tab are number values, will produce a numeric result summing these two values for the record same record in that tab.

 

Operator Description Example Result
+ addition 2 + 3 5
- subtraction 2 - 3 -1
* multiplication 2 * 3 6
/ division (integer division truncates the result) 4 - 2 2
% modulo (remainder) 5 % 4 1
^ exponentiation (associates left to right) 2.0 ^ 3.0 8
|/ square root |/ 25.0 5
||/ cube root ||/ 27.0 3
! factorial 5 ! 120
!! factorial (prefix operator) !! 5 120
@ absolute value @ -5.0 5
& bitwise AND 91 & 15 11
| bitwise OR 32 | 3 35
# bitwise XOR 17 # 5 20
~ bitwise NOT ~1 -2
<< bitwise shift left 1 << 4 16
>> bitwise shift right 8 >> 2 2

🔔 Once have created a numeric formula and saved it, you can edit it to another type of number formula, but you can not change it to display text or interval formats.

 

Math functions

Where any number field, or numeric lookup residing in the tab can be inserted as a number using the format {fieldname}. For example, ROUND({Price},2). The result of this formula, where the price is a numeric field in a tab, will produce a rounded number that is 2 decimal places for the same record in that tab. For example, a price of $3.46587222 would be rounded to $3.47.

 

Function Description Example Result
ABS Calculate the absolute value of a number ABS(-10) 10
CBRT Calculate the cube root of a number CBRT(8) 2
CEIL Round a number up to the nearest integer, which is greater than or equal to a specified number CEIL(-12.8) -12
COUNT Counts the number of items in a multi-select record field (related, lookup, or multi-select) in the tab.   Count({Jobs}) 10
DEGREES Convert radians to degrees DEGREES(0.8) 45.836624
DISTINCT

Only displays distinct values for the selection 

 

DISTINCT({Cost Values})

$1  $2    $3

 (each as their own distinct value)

An opposed to $1 $1  $1, $2, $2, $3  $2 

DIV Return the integer quotient of two numeric values DIV(8,3) 2
EXP Return the exponential value in the scientific notation of a number EXP(1) 2.7182818
FLOOR Round a number down to the nearest integer, which is less than or equal to the number FLOOR(10.6) 10
GREATEST While MIN / MAX functions work to find the smallest or largest number in a single field with multiple selections.  This function finds the highest value across the fields specified. this function works with both Number fields and Date fields. GREATEST({Field1}, {Field2}, {Field3}) GREATEST({Latest Start Date}, {Latest Term Date}, {Latest Leave Date}) 12-MAR-2023
LEAST While MIN / MAX functions work to find the smlallest or largest number in a single field with multipel selections.  This function finds the lowest value across the fields specified. this function works with both Number fields and Date fields. LEAST({Field1}, {Field2}, {Field3}) GREATEST({Latest Start Date}, {Latest Term Date}, {Latest Leave Date}) 10-APR-2017
LN Return the natural logarithm of a numeric value LN(3) 1.0986123
LOG Return the base 10 logarithms of a numeric value LOG(1000) 3
LOG Return the logarithm of a numeric value to a specified base LOG(2, 64) 6
MOD Divide the first parameter by the second one and return the remainder MOD(10,4) 2
PI Return the value of PI PI() 3.1415927
POWER Raise a numeric value to the power of a second numeric value POWER(5, 3) 125
RANDOM

Generates a random number between 0 and 1

Note: the output result of this function will be randomly different for each row in the tab.

 

🔔 The random function will randomly generate values every time the page loads. These numbers are never static; they are always random with every page load.

Random() .39
ROUND Round a number to the nearest integer or to specified decimal places

ROUND(10.3)

ROUND(10.5)

ROUND(10.498,2)

10

11

10.50

SCALE Return the number of decimal digits in the fractional part SCALE(1.234) 3
SIGN Return the sign (positive, negative) of a numeric value SIGN(-1) -1
SQRT Return the square root of a numeric value SQRT(3.0) 1.7320508
TRUNC Truncate a numeric value to a whole number of the specified decimal places TRUNC(12.3) 12
WIDTH_BUCKET Assign values to buckets in an equi-width histogram. (where the first value is the value to put into one of 5 equal buckets that span the range from 0 - 10.) WIDTH_BUCKET(5, 0, 10, 5)  3

Text string functions

Where any text-based field or text-based lookup residing in the tab can be inserted as a text for the function using the format {fieldname}. For example, CONCAT-WS(' - ',{Job Title},{JobID}). The result of this formula, where the Job Title and Job ID are both fields in the tab, will produce a result such as Project Manager - 019181 for the same record in that tab.  Note that when text is written into the formula that will be displayed, it needs to be enclosed in a single quote, but field names do not.

Function Description Example Result

ASCII

 

Return the ASCII code value of a character or Unicode code point of a UTF8 character. In the case where a string is used, this function returns the first character of the string's ASCII code value.

ASCII(‘A’)

or

ASCII({First Name})

65

COALESCE 

This function evaluates multiple arguments and will return the first non-null string it finds. If all arguments are null, a null value is returned.

COALESCE ({Preferred Name},{First Name})

Peggy

In an example where ‘First Name’ = Margaret and the ‘Preferred Name’ is Peggy, Since the preferred name is populated and not null, the value of Peggy is returned.

CONCAT

or 

||

Concatenate two or more strings into one

CONCAT({First Name},’ ’,{Last Name})

‘A’||’B’||’C’

 

Use CONCAT if null values should be ignored. Use || if null values remain represented with a placeholder.

John Smith

ABC

or it B is not present:

AC         (using CONCAT)

or

A C        (using ||)

CONCAT_WS Concatenate strings with a separator CONCAT_WS('-','A','B','C') A-B-C
DISTINCT

Only displays distinct values for the selection 

DISTINCT({JOB CODES})

MF1, MF2, MF3

 

A opposed to MF1, MF1, MF1, MFT2, MF2, MF3, MF3, MF3

FIND_STRING Finds an occurrence of searchString in sourceString starting from an optional startPosition.(startPosition is 0 by default.) If no occurrence of searchString is found, the result will be 0. The syntax for this field is: FIND_STRING(searchString text, SourceString text,[startposition integer]) FIND_STRING("World", "This is The World") 13
INITCAP Convert words in a string to title case INITCAP(‘hI tHERE’) Hi There
LEFT Return the first n character in a string LEFT(‘ABC’,1) A
LENGTH Return the number of characters in a string LENGTH(‘ABC’) 3
LOWER  Convert a string to lowercase LOWER(‘hI tHERE’) hi there
LPAD Pad on the left a string with a character to a certain length LPAD(‘123′, 5, ’00’) 00123
LTRIM Remove the longest string that contains specified characters from the left of the input string LTRIM(‘00123’) 123
MD5 Return MD5 hash of a string in hexadecimal  MD5(‘ABC’) f78fdb18bf39b23d42313
edfaf7e0a44
QUOTE_IDENT Returns the given string only when it is found in the text specified. Quotes are added only if necessary. QUOTE_IDENT(7628763) 7628763
REGEXP_REPLACE

Replace substrings that match a POSIX regular expression with a new substring. This syntax of this formula is as follows: REGEXP_REPLACE(source, pattern, replacement_string,[, flags]

 

REGEXP_REPLACE examples

this would remove all alphanumeric characters from a string:

REGEXP_REPLACE

('ABC12345xyz','[[:alpha:]]','','g')

 

This would reformat John Doe as Doe, John:

REGEXP_REPLACE('John Doe','(.*) (.*)','\2, \1')

ABE12345xyz becomes:
12345

 

John Doe becomes:
Doe, John

 

REPEAT  Repeat string the specified number of times REPEAT(‘*’, 5) *****
REPLACE Replace all occurrences in a string found with a new string specified The syntax is REPLACE (Source, string to find, string to replace found string with). REPLACE(‘ABC’, ’B’, ’A’) AAC
REVERSE Return reversed string. REVERSE(‘ABC’) CBA
RIGHT Return the rightmost (last) n characters in the string. When n is negative, return all except the first |n| characters.

RIGHT(‘ABC’, 2)

RIGHT ('ABC', -1)

BC

AB

RPAD Pad on the right of a string with a character to a certain length. The syntax is RPAD (source, number of characters to pad the value to, string to use for padding). RPAD('ABC', 6, 'xo') ABCxox
RTRIM Remove the longest string that contains specified characters from the right of the input string RTRIM('abcxxzx', 'xyz') abc
SPLIT_PART Split a string on a specified delimiter and return nth substring SPLIT_PART({Doe, John} ',  ', 2) John
STRING_AGG

Concatenate values from multiple rows into a single string, with an optional delimiter between the concatenated values. It is particularly useful when you want to aggregate data in a column into a comma-separated list or some other delimited format.

It's possible to restrict the items to just distinct items when building a string STRING_AGG function with DISTINCT: to build the string, and then in this, they use the DISTINCT keyword.

 
Here is an example of concatenating 2 fields, where the 2nd field is a multi-value where the multi-option results are and you are specifying them to be separated by a comma.
CONCAT({Name}, '--', STRING_AGG(DISTINCT {MultiOption Lookup}, ', '))

Mary -- New, Interview, 
Offer

SUBSTRING Extract a substring from a string. This function uses the following syntax: SUBSTRING(string, start_position, length ) SUBSTRING(‘ABC’, 1, 2) AB
TO_CHAR
Used to convert a timestamp, date, or number into a formatted string. Syntax:
TO_CHAR(date or number, format)
TO_CHAR ({Start Date}, DD-MMM-YYYY) 10-MAR-2023
TRANSLATE Perform one or several single-character, one-to-one translations in one operation. This function has the following syntax: (string, from, to).  TRANSLATE('12345', '134', 'ax')

a2x5

 

1 becomes a, 3 becomes x. In this example, the value 4 value is given no translation instruction in the "to" portion of the syntax so it is ignored and removed in this function.

TRIM

Remove all spaces from the start and end of a string

TRIM(‘ ABC  ‘) ABC
UPPER

Convert a string to uppercase

UPPER(‘hI tHERE’)

HI THERE

🔔 To specify a line break as your delimiter in functions you can use the following syntax: E/n. For example: STRING_AGG({Locations}, E'\n') could return an output that looks like this:

Texas
Idaho
Alabama

Date functions

Where any date-based field or date-based lookup residing in the tab can be inserted as a date for the function using the format {fieldname}.

 

Function Description  Example Result
CURRENT_DATE

Return type: DATE

Return the current date in GMT

🔔Note: use Now() if you desire a function that produces the date using the  user's local time zone.

CURRENT_DATE 04-Aug-2023
CURRENT_TIME

Return the current time

This formula uses the following syntax:

CURRENT_TIME(precision)

The precision when left unspecified is to 6 decimals.

no precision:

CURRENT_TIME()

 

precision provided:

CURRENT_TIME(2)

no precision example:

19:25:24.805985-07

 

precision provided  example:

19:25:24.81-07

DATE_PART

Return Type: Number

Get a field of a timestamp or an interval e.g., year, month, day, etc.

This formula uses the following syntax:

DATE_PART('datepart',{source})

The field is an identifier that determines what to extract from the source. Possible parts which can be extracted include:

century milliseconds
decade dow
year doy
month epoch
day isodow
hour isoyear
minute timezone
second timezone_hour
microseconds timezone_minute

 

DATE PART('year', {Date of Birth}) 

Where the person was born 2/2/2001

2001
DATE_TRUNC

Return Type: STRING

Return a timestamp truncated to a specified date part with options being:

millennium day
century hour
decade minute
year second
quarter milliseconds
month microseconds
week  

This function must be used in conjunction with the TO_CHAR function and using a valid TO_CHAR date format, as illustrated in the synax example: TO_CHAR(Date_TRUNC('date part', {field}), 'dateformat')

 

TO_CHAR(DATE_TRUNC('month', {start date}), 'MON-YYYY')

where the start date is March 1, 2022

 

(TO_CHAR added to this example to show the formatting of the date output)

MAR-2022
DATEADD

Return type: DATE

The unit options available include:

years hours
months minutes
weeks seconds
days  

Returns a date in the future or past. The syntax for this formula is DATEADD({field}, {units change by}, 'unit basis').  

DATEADD({Start Date}, -2, 'years')

 

Where the start date is 1-JAN-2022

1-JAN-2020
DATEDIFF

Return type: Number

The unit options:

months hours
weeks minutes
days seconds

Return the time difference between two dates using the unit specified according to the following syntax: DATEADD("Date field 1}, {Date field 2}, 'unit basis'). 

DATEDIFF('04/09/2023 11:00','04/10/2023 12:00', 'hours') 25
NOW

Return type: TIMESTAMPTZ

Return the current date by default. By adding the TO_CHAR function to this you can have it return date and time, or format the current date and time a different way. This time always reflects the local time of the user.

 

🔔 If using this field as a token in email or rtf fields on web forms the date will convert to GMT by default - to force local time zone in the token display use the following formula for the field that is referenced in the token: (NOW() AT TIME ZONE 'EDT')::date

🔔 Use the CURRENT_DATE function if you desire the date/time in GMT time zone.

Now()

 

or if this field will appear in email template or web form tokens use

 

(NOW() AT TIME ZONE 'EDT')::date

where EDT is the abbreviation for Eastern Time - see this list of possible times.

20-NOV-2023
WORKDAY
DATE
Returns a date that is the number of working days after the specified date. Working days will exclude weekends and an optional list of holidays, formatted as a comma-separated string of ISO-formatted dates.
This function uses the following syntax:WORKDAY({Date}, # of days, 'Holiday_date_1, Holiday_date_2,...')
WORKDAY('5/1/23', 10, '5/5/2023, 5/9/2023') 2023/05/17
WORKDAY_DIFF
WORKDAY_DIFF(starDate, endDate, holidays)
Counts the number of working days between startDate and endDate. Working days exclude weekends and an optional list of holidays, formatted as a comma-separated string of ISO-formatted dates.
 
This function uses the following syntax:WORKDAY({Date1}, {Date2}, 'Holiday_date_1, Holiday_date_2,...')

WORKDAY_DIFF('5/1/23','5/15/23',
'5/8/2023, 5/9/2023')

 

 

9
EXTRACT(EPOCH FROM...)

Used to extract the duration between two times in seconds: 

EXTRACT(EPOCH FROM({Stop}-{Start})): This part calculates the difference between the two timestamps {Stop} and {Start} in seconds. The EXTRACT function extracts a specific component (in this case, seconds) from a timestamp difference.

EXTRACT(EPOCH FROM({Stop}-{Start}))

Where Start = 21-Aug-2023 07:29:38 pm

And Stop = 21-Aug-2023 07:45:00 pm

 

 

921.864

 

Adding or modifying a function field

You can view the available properties for short text fields on the Edit field properties modal when you select Field type of Function

 

Properties of Function fields

 

After specifying a Field name (which controls how this field is referenced inside the tab) and that it will be of the type Function, you will specify the function command where you can leverage any supported operators and functions listed below. Then toggle on More field attributes to manage any additional settings which might apply. Complete the transaction at the end by clicking Save.

 

Property Description
Function command Enter the function command using the operators and functions outlined below in the supported operators and functions area of this article.
Private field Use this setting if only authorized users should be able to access this field. If this is applied, the field will be locked out from the user's view entirely unless they are authorized to access private fields. This setting works in conjunction with the security access control tab setting: View private fields. If a field is private, only users authorized to view private fields will be able to view, edit, see history, filter, or download this data. Click here to learn more.  

If text is returned:

Maximum field length

By default, the short text field can hold up to 255 characters of text. A builder can adjust the maximum field length to be shorter, if necessary. For example, you may want to reduce the maximum field length if you are building an integration with another system that has field length restrictions.

If a number is returned:

Number type

By default, numbers are specified with a type of General, which is appropriate for number values. If you want the field to hold currency or percent values, choose Currency or Percent

If a number is returned:

000's separator

By default, no number separator displays in the field, but you can choose to insert a comma (,) or a period (.) to format the number. For example, if you select a comma separator, the value 1000000 is converted to display as 1,000,000.

If a number is returned:

# of decimals

By default, there are no decimal points on a number. If you'd like to incorporate decimals into the number, specify the number of characters to display to the right of the decimal point. For example, if you are using a number field to track GPA, you may want to specify 2 for # of Decimals so that the GPA can read like this: 4.00.

 

If a number is returned:

 

Symbol

This property only displays once you select currency as the type of number you plan to track. Use it to specify the correct currency symbol for what you plan to track in the field.

 

 

If a date is returned:

 

Date format

Choose the format for how you would like the date to display.  The following options exist:

Format Example date display
DD-MM-YYYY* 08-Sep-2020
DD/MM/YYYY 08/09/2020
MM/DD/YYYY 09/08/2020
YYYY-MM-DD 2020-09-08
Day of week, Month, DD, YYYY Wednesday, September 9, 2020

 *Default date format

If a date is returned:

Include time

If you want the time to display with the date, toggle on this option. You can then make selections for whether the time uses a 12-hour or 24-hour clock, whether seconds should be included, and whether the time displays in GMT or in the user's browser time (local time zone option that controls the time zone of the display).

Field callout

If you enter any text into the Field callout textbox, the information (i) icon appears to the left of the field name, and the text you entered displays when users move the cursor over this icon. Enter text here if you want to provide information to help the user learn more about how to use the field.

Important notes

🔔 Any lookup fields that look up numeric fields are technically strings in GraceBlocks;  they will need the CAST function applied to use this number in a formula. Here's an example using the CAST Function inside a larger formula.

Here are two examples using the CAST function with other functions to achieve a more complex result:

Example scenario: Let's say we've done market analysis for job titles in a tab, and we now want to pull that data into the employee's tab so we can compare the employee's current salary {Annual Salary} to where it falls relative to the market.  We want to first identify anywhere that the employee's salary is either over the {Market max} or under the {Market Min} value, and by how much.  Then we want to calculate the value for how much the employee is over by as a % of the {Market Median}. For this example, the market max, median, and min values are all specified in a market analysis tab and looked up in the Employees tab where this example is being built).

Step 1: We need a new field {Over or Under} that identifies how much are we over or under the market in cases where the employee's salary is outside the market range identified. 

This will be done as a case statement that looks like this:

CASE
WHEN {Annual Salary} > CAST({Market Max} as numeric) then {Annual Salary}-CAST({Market Max} as numeric)
WHEN {Annual Salary} < CAST({Market Min} as numeric) then {Annual Salary}-CAST({Market Min} as numeric)
end

CASE
WHEN {Number to compare} > CAST({Field_8} as numeric) then {Number to compare}-CAST({Field_8} as numeric)
end

Step 2: Now we'll add a field {Percent Over or Under Median} that calculates the {Over or Under} value as a % of the median salary and is formatted as a % value.  

       Part 1:  the formula:    {Over Max or Under Min} / CAST({Market Median} as numeric)

 

Part 2: format the field: Then once this value is calculated as a number, formate the property of this field using the Numeric format options to be displayed as a Percent value with # of decimals = 2.

Example Result:

 

 

🔔It is possible to use formulas to construct web forms that are pre-populated with values by following the steps below.  This can be done to create new records or update existing records.  The steps for both scenarios are outlined below:

Creating new records: This approach works well when you want users to easily create records in a different but related tab. 

  1. Build the web form you wish to pre-populate with values.  Copy the URL to the form and put it into notepad.
  2. Create a Concat formula that includes the values that you need as tokens in notepad.  
  3. Paste it into a formula field for a tab where you'd like this action to be available.
  4. Select URL under More field attributes > Formatting Options.
  5. Toggle on Convert URL to button.
  6. Enter the name for your button.

🔔Related records in the form can be pre-selected and populated using the system ID token. 

Example Formula:

Concat('https://dev.graceblocks.com/form?x=ODl8Z3JhY2VibG9ja3MtMXwyMTM=&internal=true&updateBaseRow=true&field-5=',{System ID}))

Example Result:

https://dev.graceblocks.com/form?x=ODl8Z3JhY2VibG9ja3MtMXwyMTM=&internal=true&updateBaseRow=true&field-5=1

Where

🔔 &Field-5=1 (where 1 = the {Sysstem ID in this example) identifies the related record you are currently working on to allow it to add a related record of this record in the corresponding tab.

🔔 Use &internal=true to indicate the form is being filled out inside of GraceBlocks

🔔 Use &updasteBaseRow=true to indicate your are filling out a form that will add a record to a different tab on Graceblocks

 

 

Updating existing records: This approach works well when you want users to easily update a record while you are working with it

  1. Build the web form you'd like to use for updating your record.  Copy the URL to the form and put it into notepad.
  2. Go to web form settings and toggle on: Update vs. create new record when duplicates are identified.
  3. Select System ID as your DUPLICATE CRITERIA and save the updated settings.
  4. Create a Concat formula that adds this text to the end of your record: GENERATE_FORM_ID({System ID}),'&prefill=true'
  5. Paste the resulting formula it into a formula field on the tab where you will be updating records.
  6. Select URL under More field attributes > Formatting Options.
  7. Toggle on Convert URL to button.
  8. Enter the name for your button.

Example Formula:

CONCAT('https://dev.graceblocks.com/form?x=MTAxfGdyYWNlYmxvY2tzXzAxfYV5Mg==&id=',GENERATE_FORM_ID({System ID}),'&prefill=true&internal=true')

Example Result:

https://my.graceblocks.com/form?x=MTAxfGdyYWNlYmxvY2tzXzAxfDY5Mg==&id=MTU4Nzgy&prefill=true&internal=true 

(Note, only include &internal=true if the form is to be clicked while the user is logged into GraceBlocks. This added syntax in the url will strip the outer boarders from the form as well as the form icon from the tab.) 

 

🔔 Formula fields can not be converted into other field types.  You must always create them from scratch.  Other field types be converted into functions, however, doing this will result in abolishing all of the data in that field and repurposing it to display the value resulting from the formula.

🔔 Editing functions associated with a formula field is possible, however, the new formula must match the data type of the original formula.  For example, number formulas can be converted into other number formulas provided they are the same type of number. For example, an ABS number which is an integer format can not be converted into a SQRT formula which would have decimals.

🔔 Calculating the time in hours to a 2-decimal number precision can be done using a formula that subtracts the time between two time periods.  

ROUND(CAST(EXTRACT(EPOCH FROM({Stop}-{Start})) / 3600 AS NUMERIC), 2)

Explanation breakdown: We have two timestamps {Stop} and {Start} in hours, rounded to two decimal places. Let's break down the components step by step:

  1. EXTRACT(EPOCH FROM({Stop}-{Start})): This part calculates the difference between the two timestamps {Stop} and {Start} in seconds. The EXTRACT function extracts a specific component (in this case, seconds) from a timestamp difference.
  2. / 3600: The result obtained from the previous step, which is the time difference in seconds, is divided by 3600 to convert it to hours. This is because there are 3600 seconds in an hour.
  3. CAST(... AS NUMERIC): The result of the division is then cast (converted) to a numeric data type. This might be necessary depending on the data types of the {Stop} and {Start} timestamps. 
  4. ROUND(..., 2): The numeric result from the previous step, which represents the time difference in hours, is rounded to two decimal places using the ROUND function.

The entire formula is then used to check if the calculated and rounded time difference in hours is equal to something (not provided in your example). Presumably, you would replace the ... with a specific value to which you're comparing the calculated time difference.

🔔 If is possible to calculate a duration of time by subtracting one date from another. If the date is a date/time field - the interval will show in hh.mm.ss format eg: 5:22:21 which represents 5 hours, twenty-two minutes, and twenty-one seconds.  If the duration is two whole date fields then the value will return a number of days, eg: 2 days.  When exporting this data via API, durations will export as text values.  A formula to convert this value to something numeric should be used if a number value is desired via API export.

🔔 Functions reference the text name of the field.  If the name of the field changes, the formula will still work.  For example, if you have a field called "Cost" and you change the field name to "Price," the formula will still work. However, if you try to edit this formula, you will need to change the field label to the new value. If you try to save a function that names a field that has been changed, the system will throw an error and will not let you save your changes.

🔔 The period character is special in the formatting of a number to a string when using the TO_CHAR Function. It can only be used once in the formatting. You can use other characters however, like a comma or a hashtag, but not more than one period.

🔔 Most functions are Postgres native functions, but some are custom-built inside of GraceBlocks. Where provided, click the hyperlink in the first column of these tables to learn more about a specific function directly from the Postgres documentation for more examples.