Using Formulae

- Using Formulae


Click on Refresh preview each time you add a column, criteria or summarise your data.  This enables you to check your report is building correctly and 'sense-check' that it's displaying the results in the way you require.

Related Forum

Related Blog Posts

Workbooks reporting allows you to build a Calculated Column using formulae.  The formulae are based on MySQL statements (which is simply a language that can be used to extract information from a database).  Much like formulae in spreadsheets, formulae in Workbooks can be used for many purposes, including:

  • Calculations (for example, additions, subtraction, multiplication, etc);
  • Comparing data (for example, if two values are the same, display 1 and if they're different display 0);
  • Displaying dates and times in relation to another specified date and time;
  • Formatting data such as dates, times, rounding decimal places, etc;
  • Converting data, such as numbers into strings;
  • Concatenating data (displaying a number followed by a percentage symbol, for example).

If you want to apply a simple calculation that generates any of the following:

  • the total of the values;
  • the minimum of the values;
  • the maximum of the values;
  • the average of the values;

you can do this by adding a column for the amount and ticking the checkbox next to Summarise the values.  This will open a field called Calculate where you can use the dropdown picklist to control what's being calculated, as illustrated in the screenshot below.


If you want to add a more complex calculation you should add a Calculated Column.  The table below gives some MySQL statements that you might find useful when putting together Reports in Workbooks.  It is not intended to be an exhaustive list but includes some of the more commonly used expressions. For more information on how these MySQL statements work, we recommend that you consult a specialised manual.  Of course, if you need any help with reporting, try the reporting section on the forum.


Test if conditions are true or false 


IF(logical_test, value_if_true, value_if_false)


logical_test:  the condition you want to check

value_if_true:  the value to return if the condition is true

value_if_false:  the value to return if the condition is false

eg, IF(activity_type LIKE 'Phone Call', 'True', 'False')

on an Activity report would display a row populated with True for every Phone Call activity and False for any other activity type.

Compare a value to a series of values and return a specified value




CASE column_name WHEN choice THEN returnvalue ELSE


CASE  status_name
WHEN 'Open' THEN 'Not Started'
WHEN ' Closed' THEN 'Finished'
ELSE 'In Progress'

on a Case report would create a column which shows Not Started for any Case with a Status value of Open and Finished for any Case with a Status value of Closed.  In addition, it will show In Progress for Cases that have a Status value of anything other than Open or Closed.

Add a specified amount of time to a date 



this adds 7 days to the current date

Note:  The following interval types can be used in place of DAY:  SECOND, MINUTE, HOUR, WEEK, MONTH, YEAR 

Subtract a specified amount of time from a date 



this subtracts 1 month from the current date

Note:  The following interval types can be used in place of MONTH:  SECOND, MINUTE, HOUR, DAY, WEEK, YEAR 

Format a date 


DATE_FORMAT(column_name, '%D %M %Y')

eg, DATE_FORMAT(created_at, '%D %M %Y')

would show the date a record was created with the day displayed as an ordinal number followed by a four digit year, for example 1st January 2010.

To display a date as numbers, use the same letters as above but enter them in lower case:

eg, DATE_FORMAT(created_at, '%d %m %y')

which would show the same date as 01 01 10.

There are additional ways to format a date, which can include the weekday, as shown below:


Shows the abbreviated weekday name according to the current locale.


Shows the abbreviated month name according to the current locale.

Calculate the difference in days between two dates 



eg, DATEDIFF(CURDATE(), created_at)

would show the number of days between today and the date the record was created.

Insert the current date 



Type in the above to return the current date. 

Insert the current time



Type in the above to return the current time. 

Calculate the mean average of a group of numbers 



eg, AVG(amount)

on an opportunity report would return the mean average of the opportunity amounts. 

Add numbers 

eg, first_column_name+second_column_name

Subtract numbers 

eg, first_column_name-second_column_name

Multiply numbers 

eg, first_column_name*second_column_name

Divide numbers 

eg, first_column_name/second_column_name

Find the total of a series of numbers 



eg, SUM(amount)

on an opportunity report would return the total of the opportunity amounts. 

Display a specified number of decimal places 




integer is the number of decimal places you want to display

eg, FORMAT(AVG(amount),5)

on an opportunity report would return the average opportunity amount to 5 decimal places.

Count the number of records 




Display text in upper case 




Display text in lower case 




Combine two or more fields 


CONCAT(first_column_name,' ',second_column_name,' ',third_column_name)

Summarise a column into a string




GROUP_CONCAT(column_name SEPARATOR ', ')

eg, GROUP_CONCAT( campaign_membership.campaign_name SEPARATOR ', ')

on a Person report will join together all the Campaigns of which the Person is a member, separated by a comma.  (Remember that you'll need to summarise this report in order to see each person on a separate row and we recommend summarising by the Object Reference.)