Calculated fields

Calculated fields allow you to compute a field with values from other fields from the same entity (such as a Shot or an Asset). You can use calculated fields to make it easier and faster to find useful information.

Add a calculated field the same way you add any other field type. You will see the list of available fields for the specific entity you’re using under the “Available Fields” section. If you add additional fields of supported types to your page, they will appear under the list of Available Fields on your Calculated fields.

Make sure you use the format listed under “Available Functions” in your formula, like in the example below.

Calculated fields

Type in your formula. If the formula uses the “Float” output type, you can choose the Display Format, which will override the default float format for this particular field.

Note: Cells will turn red if there are errors that will cause the formula to fail.

Please also note you cannot divide by zero. Doing so will produce an error.

All calculated fields are “live,” which means if you update any inputs in your field you will see those changes immediately.

Once you have configured your field, you can choose to sort, group, or summarize on the field. You can also filter on a calculated field. Additionally, you can hover over the column header of a calculated field to see the formula.

Tooltip

Additionally, you can graph on a calculated field. In your graph, you can choose to group or summarize on a calculated field, which allows for some very powerful graphing capabilities.

Graph by calculated field

Available functions

Math

Name Description Syntax
+ Addition value1 + value2
- Subtraction value1 - value2
* Multiplication value1 * value2
/ Division value1 / value2

String

Name Description Syntax Example Result
CONCAT Combine strings CONCAT(string1, string2) CONCAT(“Shot”, “gun”) “Shotgun”
UPPER Uppercase string UPPER(string) UPPER(“Shotgun Software”) SHOTGUN SOFTWARE
LOWER Lowercase string LOWER(string) LOWER(“Shotgun Software”) shotgun software
LEFT Returns part of the string from the beginning of the specified string LEFT(string, [number_of_characters]) LEFT(“ab_0124”, 2)
LEFT(“Shotgun Software”)
LEFT(“ab_0124”, 0)
“ab”
“S”
“”
RIGHT Returns part of the string from the end of the specified string RIGHT(string, [number_of_characters]) RIGHT(“ab_0124”, 4)
RIGHT(“Shotgun Software”)
RIGHT(“ab_0124”, 0)
“0124”
“e”
“”
MID Returns part of the string, taken from a segment of the string MID(string, starting_at, extract_length) MID("ab_0124", 3, 1) “_”
LEN Length of a string LEN(string) LEN("Shotgun Software") 16

Definitions of string arguments

Name Description
number_of_characters The number of characters to return from the left or right side of string. (This is optional, and set to “1” by default.)
starting_at The starting point from the left of the string from which to begin extracting. The first character in the string has the index 1.
extract_length The length of the segment to use.

Notes about strings

  • 0 is a valid input for number_of_characters and will cause LEFT and RIGHT to return the empty string (“”).
  • If the end of string is reached before extract_length characters are encountered, MID returns the characters from starting_at to the end of string.
  • To return the contents from starting_at to the end of string, use LEN to calculate the length of the string that will be returned rather than simply specifying a large number for extract_length.
  • LEN counts all characters, even spaces and nonprinting characters. In cases where LEN returns unexpected values, ensure that there are no such characters in text.

Type conversion

Name Description Syntax Output Type Example Result
FIXED Formats a numeric value as text to display a specific number of decimal places. FIXED(number, [number_of_places]) Text FIXED(3.141592,4)
FIXED(3.141592,0)
FIXED(3,3)
3.1416
3
3.000
TO_FLOAT Converts a numeric value (number, currency, percent) to a float. TO_FLOAT(number) Float TO_FLOAT(11)
TO_FLOAT({sg_percent}) // {sg_percent} = 40%
TO_FLOAT(sg_amount}) // {sg_amount} = $200
11.00
0.40
200.00
TO_CURRENCY Converts a numeric value (number, float, percent) to a currency. TO_CURRENCY(number) Currency TO_CURRENCY(1.479531)
TO_CURRENCY(10)
TO_CURRENCY({sg_percent}) // {sg_percent} = 40%
$1.48
$10.00
$0.40
TO_PERCENT Converts a numeric value (number, float, currency) to a percent. TO_PERCENT(number) Percent TO_PERCENT(0.4)
TO_PERCENT(0.40926)
TO_PERCENT(101)
40%
40%
10,100%

Notes about type conversions

  • The number is the number to format.
  • The value is the numeric value to be converted to a float, currency, or percentage.
  • The number_of_places is the number of decimal places to display.
  • The maximum value for number_of_places is six. If the number has fewer than number_of_places significant digits, zeros will be appended. If it has greater than the number_of_places significant digits, the number will be rounded to the correct number_of_places, rather than truncated.
  • The TO_FLOAT returns the value converted to a float, with the standard interpretation that 1 = 100%. Since the output type will be a float, you can choose how many decimal places to display in the result.
  • The TO_CURRENCY returns the value converted to a currency field. It will obey your Site Preferences for currency display.
  • The TO_PERCENT returns the value converted to a percentage, with the standard interpretation that 1 = 100%. The value is floored to get to the nearest whole number percent.

Error messages

You may see different error messages in your calculated fields, either in the formula editor itself or in the results of the calculation.

Example calculations

Below are some examples of formulas for calculated fields.

Description Formula Output format
Cut length {sg_cut_out} - {sg_cut_in} + 1 Float (10)
Cut summary CONCAT({sg_head_in}, " [", {sg_cut_in}, " - ", {sg_cut_out}, "] ", {sg_tail_out}) Text
Projected shot cost {sg_shot_bid} * {sg_shot_cost} Float
Shot prefix for reference CONCAT("A_", {code}) Text
Trim off last two characters of a string LEFT({string_field}, LEN({string_field}) - 2) Text

Additionally, calculated fields are available via the API.

Follow

13 Comments

  • 0
    Avatar
    Dennis --DJ-- Hauck

    OMG, this is Awesome!  I've wanted these in the web UI for years.  We always built event daemon plugins to do these basic functions, which seemed like overkill.  Great add team, thanks!

  • 8
    Avatar
    Tony Aiello

    Woohoo, seconded!  So thrilled for these.  Here are some ideas for future function additions based on other existing use-cases we have that we're either doing with daemon plugins or by hand:

    1. time deltas!  e.g. on a Task with a {due_date}, calculate a date N days into the future from it.  Excel doesn't seem to have great syntax for this, so maybe a python inspiration TIMEDELTA({due_date},21) could return a date 3 weeks into the future from a Task's due_date.  Alternately, functions to encode the units of the delta e.g. sg_future_date = {due_date} + WEEKS(3).  These should still obey WorkScheduleRules, so if a calculated future_date lands on a non-working day, I'd expect it to get offset to the next real working day.

    2. string slicing ala Excel's text functions (since it seems like you're going for Excel, with the name "CONCAT"):  how about LEFT(string,N), RIGHT(string,N), MID(string,P,N):  Use-case: calculate a HumanUser's initials e.g. CONCAT(LEFT({firstname},1), LEFT({lastname},1))

    3. list selectors!  for example a syntax like {task_assignees}[0] or {task_assignees.0} or whatever could return that 0'th entry from the multi-entity assignees field on a task, thus returning a single-entity field and making it flow-through-able!  Literally 90% of the time, we're assigning tasks to just a single person or group.  (29,125 tasks with only 1 assignee out of 32,667 with assignees)

    4. support for Query Fields as inputs.  Note that doing so could be one way to solve the long-standing feature request for being able to sort + group + filter by Query Fields: create a calculated field that just returns the value of a query field then sort / group / filter by that calculated field.

    5. error-handling.  provide a place to enter a "default" field to return if a calculation cannot be evaluated, like the except: clause for a DivisionByZero error.

    Edited by Tony Aiello
  • 7
    Avatar
    Jeremie Passerin

    Would be nice to also have Max(), Min() method

  • 0
    Avatar
    Jacob Medendorp

    Just a small request - it would be nice if in the available fields section, it also listed the field type.

    Thanks for this feature!

  • 1
    Avatar
    Ziah Fogel

    Thanks for the feedback, everyone! We've actually already got one of these prepared for the next release - listing the available field type in the UI. Working on some duration-related things too - so more is on the way! :)

     

  • 1
    Avatar
    Juanmaria Garcia

    Very good! At last.

    Percentage format would help, also

     

  • 0
    Avatar
    Benoit Leveau

    It's a great addition!

    We'll need a rounding function so we can compute overscan resolutions. Currently, using a formula like:

    CONCAT({sg_overscan}*{sg_width},"x",{sg_overscan}*{sg_height})

    gives a result of: 

    2115.584x1194.148

    and we'd like to show it as:

    2116x1194

    Also, very minor glitch in the UI: in the list of Availale Functions, the 3rd one is listed as "+    Multiplication".

     

  • 0
    Avatar
    Gavin Greenwalt

    {sg_sequence} isn't supported though? :(  That's the field I really wanted to do calculated fields for.  

    e.g.    Project_Sequence_Shot

  • 0
    Avatar
    Marcel Tie

    Great stuff!

    Would be nice, if the date fields on task entity could be available as well so that we can get more calculated duration (in days).

    Further, the thoughts from Tony are really considerable in my point of view!

    Cheers.

  • 1
    Avatar
    Tony Aiello

    Here are a couple more string-processing formula requests!

    • DECODE('hex') -- convert hex-encoded strings e.g. session_uuids back to ASCII text
    • STRIP() -- remove whitespace characters from the beginning and end of strings

    This is so we could have a calculated field that "decrypts" our encoded os.environ['USER'] as per https://support.shotgunsoftware.com/hc/en-us/community/posts/115004295453

  • 1
    Avatar
    Nils Lerin

    +1 for adding support to query fields. Would help us immensely 

  • 1
    Avatar
    lozo vfx

    Other little request, it would be great to be able to evaluate Checkboxes at least as booleans, 0 1

     

  • 1
    Avatar
    Julien Brasseur

    Could we have a length or sum function to get the number of entities of a field ? Something like LEN({sg_actors})

Please sign in to leave a comment.