Skip to content

Formulas

Formulas can be used to do calculations when item amounts are subject to change and/or depend on other amounts or payslip periods. They allow you to automate and customise how values are determined within the system. Formulas can be applied to both custom and system items.

There are two main ways in which formulas can be used:

As a fixed formula for a custom item

You can set up a custom item that uses a fixed formula, as follows:

  1. Go to Settings > Custom Items > Add Custom Item.
  2. Click the type of custom item. See the Custom Items help page for more information.
  3. Enter a Name, and select "Formula" as the Input Type.

    Applicable custom item types

    The "Formula" Input Type is available only for custom deductions, benefits, and employer contributions.

  4. An additional field will then appear where you can enter your formula.

    Use of an equal sign

    The example formulas below include an equal sign (=), but it is not necessary when you enter a formula in a Formula field.

  5. Complete any other relevant fields, and click Save.

In a numeric input field

You can use a formula in any numeric input field of an employee or payslip item – as long as you start the formula with =.

Basic Formulas

Formula inputs can consist of variables, numbers, and basic mathematical operators such as +, -, *, /, and ( ).

Examples – Basic formulas

Here are some examples of basic formulas:

  • = normal_rate * 40 * 25
  • = (basic_salary + normal_pay) / 4.3333 * 0.3333
  • = max(0, 300 - mtd_before_current('raf_contribution'))

Variables and functions which can be used when creating formulas are:

Variables

  • basic_salary: Basic Salary (salaried employees)
  • normal_pay: Basic Hourly Pay (hourly paid employees)
  • normal_rate: Hourly Rate
  • shifts_worked: Number of shifts worked
  • total_income: Total income
  • periods_in_year
  • hourly_paid
  • weeks: Number of weeks in the pay period. Use it to turn an amount set per week, such as a weekly levy, into the amount for each payslip. It is counted as follows:
    • Weekly: 1
    • Every 2 weeks: 2
    • Monthly: the number of Fridays in the month (4 or 5)
    • Monthly, with a Last day of month other than "Month End": 4, even if the period contains five Fridays. The exception is a period ending on the 29th or 30th, which can give 5.
    • Twice a Month: not suitable
    • Every 4 weeks: not suitable. For employees on this pay frequency, use a separate custom item with "Fixed Amount" as the Input Type, set to four times the weekly amount.
  • default_days_worked: For monthly employees, equal to their full days per week (Regular Hours) × 4.333. For weekly paid employees, full days per week (Regular Hours).
  • days_with_leave_for_system_type:

    • For example: = normal_rate * days_with_leave_for_system_type('unpaid'). This would be the number of days taken with unpaid leave.

    Days with leave vs days of leave

    This considers days with unpaid leave, not days of unpaid leave.

  • raf_contribution: The total amount contributed to a Retirement Annuity Fund – to be used with the mtd_before_current function. (It includes the contributions of both the employee and employer.)

Functions

  • min: Used to select the lowest of the values in the list provided to it.
    • For example: = min(50,100) = 50
  • max: Used to select the highest of the values in the list provided to it.
    • For example: = max(50,100) = 100
  • round: The number in brackets will be rounded up or down depending on the decimal. This functions as per the regular rounding of numbers.
    • For example: = round(1.1) = 1, and = round(1.5) = 2
  • ceiling: Rounds up the number in brackets to the nearest whole number.
    • For example: = ceiling(1.1) = 2
  • floor: Rounds down the number in brackets to the nearest whole number. The number will always be rounded down regardless of the decimal point.
    • For example: = floor(1.1) = 1, and = floor(2.7) = 2
  • mtd_before_current: This function accepts a string argument representing an account name, e.g. basic_salary. It will return the month-to-date value of the given account – but excluding the value for the current payslip.
    • For example: = max(0, 300 - mtd_before_current('raf_contribution')). When used in the Amount field, this will result in a R 300 RAF Deduction on the first payslip in any given month for non-monthly employees. Note that you can use this formula when adding the Retirement Annuity Fund system item to the employee's profile.

Examples – Variables and functions

Example 1: Bargaining Council Levy

An employer must make a contribution that is 0.32% of the employee's hourly pay, with a maximum contribution of R 4.26. Since there is a maximum, the formula must select the lowest of option (1), which is R 4.26, and option (2), which is the employee's pay multiplied by 0.32%.

= min(4.26, (normal_pay * 0.0032))

Example 2: Trade Union deduction

An employee must make a contribution of 1% of their hourly pay, plus R 1.80. Before the R 1.80 is added, the minimum contribution is R 9.13, and the maximum contribution is R 16.73.

= min(16.73, (max(9.13, (normal_pay * 0.01)))) + 1.80

Example 3: Weekly bargaining council levy

A monthly employee must contribute R 3.84 to a bargaining council levy for each week in the pay period. Because a month has four or five weeks, multiply the weekly amount by weeks, and set it up as a custom item with a fixed formula. Use the weekly amount from your own agreement.

This gives R 15.36 (3.84 × 4) in a month with four Fridays, and R 19.20 (3.84 × 5) in a month with five. For an employee on the Every 2 weeks pay frequency, the same formula gives R 7.68 (3.84 × 2).

= 3.84 * weeks

"IF" Statements

General IF statements

The IF function returns one value if the specified condition is true and another if it's false. The IF statement is also known as a logical formula: If, then, else. If something is true, then do this; else/otherwise, do that.

The IF statement works as follows:

if (condition, true statement, false statement)

Syntax errors and arguments

If you try to use an IF statement, but you get an error message about the syntax being wrong, or there being too many or too few arguments, please check that your IF statement is complete and follows the same pattern as above. Also, see the examples below.

Example – IF statement

Suppose that the company deducts a staff social fund contribution based on how much an employee earns. If the employee's salary is greater than R 10,000, then the contribution is R 100, but if the employee earns less than R 10,000, then the contribution is R 80.

The formula will be written as:

= if (basic_salary > 10000, 100, 80)

This means that if the basic salary is greater than R 10,000, the result will be R 100, and if it's less, it will be R 80.

Nested IF statements

A nested IF statement is an IF statement within an IF statement. It works as follows:

if (condition, true statement, if (condition, true statement, false statement))

Example – Nested IF statement

Suppose that the company deducts a staff social fund contribution based on how much an employee earns. If the employee's salary is greater than R 10,000, then the contribution is R 100, but if the employee earns between R 5,000 and R 10,000, then the contribution is R 80, and if they earn less than R 5,000, it is R 60.

The formula will be written as follows:

= if (basic_salary > 10000, 100, if (basic_salary < 5000, 60, 80))

This means that if the basic salary is greater than R 10,000, the result will be R 100. Otherwise, if the salary is less than R 5,000, the result will be R 60; otherwise, it will be R 80.