Subtract two numbers of which one is the result of a sum

Hi everyone,

is it possible to subtract two numbers of which one is the result of a sum? All without using third-party fields where to calculate the sum of the two numbers.

Below is the example:

  • "x-y" where "y" is equal to "a+b" --> so x-(a+b)

a+b could be a result of a rollup sum

Thank you!

  • Hi Mirco Marcigaglia,

    Yes.

    A calculated field function can accept as parameters:

    1. values (strings, numbers, boolean) - "word soup", 24, true

    2. field variables - $name, $quantity

    3. other functions - add(24,$quantity)

    So, if you want to make the calculated field formula for x-(a+b), you would:

    subtract(x,add(a,b))

    A thing to keep in mind is that each function has stipulations about the data type. You can't do math on strings and boolean, for example. So, if you have a number in a text field, for example, and you want to use it in some math, you have to first use a function to convert it to a number.

    For example:

    add(number($textfield),$integer)

    Also, don't take for a granted that an empty field will be treated as a zero in math functions. To account for this, I wrote this knowledge base article.

    I hope this helps!