Math Formula Operators and Functions in Salesforce

HELLO Salesforce Thinkers, In our previous blog we learned about Logical Formula Functions in Salesforce, In this blog we are going to learn about “Math Formula Operators and Functions in Salesforce”.

Math Formula Operators:

We have the following Math Operators in Salesforce.

+ (Add) :

Calculates the sum of two values.

value1 + value2

Replace each value with merge fields, expressions, or other numeric values.

(Subtract) :

Calculates the difference of two values.

value1 – value2

Replace each value with merge fields, expressions, or other numeric values.

*(Multiply) :

Multiplies its values.

value1 * value2

Replace each value with merge fields, expressions, or other numeric values.

/ (Divide) :

Divides its values.

value1 / value2

Replace each value with merge fields, expressions, or other numeric values.

^ (Exponentiation) :

Raises a number to a power of a specified number.

Number^integer

Replace number with a merge field, expression, or another numeric value, replace integer with a merge field that contains an integer, expression, or any integer.

() (Open Parenthesis and Close Parenthesis) :

Specifies that the expressions within the open parenthesis and close parenthesis are evaluated first. All other expressions are evaluated using standard operator precedence.

(expression1) expression2…

Replace each expression with merge fields, expressions, or other numeric values.

Math Formula Functions:

We have the following Math Functions in Salesforce.

ABS :

Calculates the absolute value of a number. The absolute value of a number is the number without its positive or negative sign.

Syntax: ABS(number)

Replace number with a merge field, expression, or other numeric value that has the sign you want removed.

Example : ABS(Total Amount) calculates the positive value of the  Total Amount regardless of whether it is positive or negative.

CEILING :

Rounds a number up to the nearest integer, away from zero if negative.

Syntax: CEILING(number)

 Replace number with the field or expression you want rounded.

Example : CEILING(4.5) returns 5, which is 4.5 rounded up to the nearest integer.

CEILING(-4.5) returns -5, which is -4.5 rounded away from zero for a negative number.

DISTANCE :

Calculates the distance between two locations in miles or kilometers.

Syntax: DISTANCE(mylocation1, mylocation2, ‘unit’)

Replace mylocation1 and mylocation2 with two location fields, or a location field and a value returned by the GEOLOCATION function. Replace unit with mi (miles) or km (kilometers).

Notes:

The DISTANCE function returns a number data type.

DISTANCE is the only formula function that can use GEOLOCATION parameters.

The DISTANCE function isn’t available in reports, but it can be used in list views. To use DISTANCE in our reports, we can set up a formula field, and then reference the field in our reports.

EXP :

Returns a value for e raised to the power of a number we specify.

Syntax: EXP(number)

Replace number with a number field or value such as 3.

Example : EXP(3)

This formula returns the value of e to the third power.

FLOOR :

Returns a number rounded down to the nearest integer, towards zero if negative.

Syntax: FLOOR(number)

Replace number with a number field or value such as 2.3.

Example :

FLOOR(3.5) returns 3, which is 3.5 rounded down to the nearest integer.

FLOOR(-3.5) returns -3, which is -3.5 rounded towards zero for a negative number.

GEOLOCATION :

Returns a geolocation based on the provided latitude and longitude. Must be used with the DISTANCE function.

Syntax: GEOLOCATION(latitude, longitude)

Replace latitude and longitude with the corresponding geolocation, numerical code values.

LN :

Returns the natural logarithm of a specified number.

Syntax: LN(number)

Replace number with the field or expression for which you want the natural logarithm.

Note:

The LN function is the inverse of the EXP function.

LOG :

Returns the base 10 logarithm of a number.

Syntax: LOG(number)

Replace number with the field or expression from which you want the base 10 logarithm calculated.

MAX :

Returns the highest number from a list of numbers.

Syntax: MAX(number, number,…)

Replace number with the fields or expressions from which you want to retrieve the highest number.

MCEILING :

Rounds a number up to the nearest integer, towards zero if negative.

Syntax: MCEILING(number)

Example :

MCEILING(2.5) returns 3, which is 2.5 rounded up to the nearest integer.

MCEILING(-2.5) returns -2, which is -2.5 rounded up towards zero for a negative number.

MFLOOR :

Rounds a number down to the nearest integer, away from zero if negative.

Syntax: MFLOOR(number)

Example :

MFLOOR(2.5) returns 2, which is 2.5 rounded down to the nearest integer.

MFLOOR(-2.5) returns -3, which is -2.5 rounded away from zero for a negative number.

MIN :

Returns the lowest number from a list of numbers.

Syntax: MIN(number, number,…)

Replace number with the fields or expressions from which you want to retrieve the lowest number.

MOD :

Returns a remainder after a number is divided by a specified divisor.

Syntax: MOD(number, divisor)

Replace number with the field or expression you want divided, replace divisor with the number to use as the divisor.

ROUND :

Returns the nearest number to a number you specify, constraining the new number by a specified number of digits.

Syntax: ROUND(number, num_digits)

Replace number with the field or expression you want rounded, replace num_digits with the number of decimal places you want to consider when rounding.

Notes:

Enter zero for num_digits to round a number to the nearest integer.

SQRT :

Returns the positive square root of a given number.

Syntax: SQRT(number)

Replace number with the field or expression you want computed into a square root.

Example: SQRT(25) returns the square root of 25, which is 5.

Notes:

Calculating the square root of a negative number results in an error on the detail page.

Thanks for reading…

Leave a comment