Skip to main content

Custom Functions

Define custom functions to reuse throughout your notebook, making calculations easier to understand.

If you don't want to define your own, Decipad already supports a list of basic functions out of the box:
Decipad Functions List →

Create Custom Functions

Syntax

CustomFormulaName (first argument, ..., last argument) = your custom expression

To create a custom function in Decipad:

  1. Add an Advanced formula block by clicking the + button next to an empty line and selecting "Advanced formula".

  2. Choose a unique name for your custom function that differs from any variables or unit name.

  3. Specify the arguments for your custom function by separating them with commas and enclosing them in parentheses (first argument, ..., last argument). These arguments are the variables that can be reused in your formulas.

  4. Define your custom function using an equal sign, followed by your custom expression = your custom expression.

  5. You can now reuse your custom function in other formula blocks by calling it as YourCustomFunction(YourArguments).


Example

Let's consider an example where you want a custom function that always applies a 10% discount to a price.

1
💡
2
  1. 1.
    Start by defining your custom function applyDiscount(Price) = Price - 10% on an Advanced Formula block.
  2. 2.
    Then reuse it on any formula block just by calling its name and passing the arguments.
    In this case: Price.
3
4
💡

Custom functions can have more that one argument. Just separate them with a comma.

  1. 3.
    On this example lets consider a special discount for your VIP clients. Add an extra argument to help with your custom formula logic called ClientTier.
  2. 4.
    Reuse your custom function ApplyDiscount(Price, ClientTier) in any other formula block.
    For a Price = $100 the discount will be 20%, totalling $80.
5
6

The advantage of custom functions is that you can reuse your calculations with different inputs.

  1. 5.
    For example, when you apply a discount for a regular customer on a Price of $100, they will pay $90.
    A 10% discount.
  2. 6.
    Your VIP customer will pay $160 on a purchase of $200. A 20% discount.