# How to Create a Custom Math Formula

*Skill Level: Intermediate*

## Before You Begin

* Should have knowledge about [Databases](https://help.adalo.com/database)
* Should have knowledge of [Magic Text](https://help.adalo.com/component-basics/inserting-dynamic-text)

## Walkthrough

#### **Using Custom Formulas with Magic Text**

When adding Magic Text, you’ll notice the option **"New Formula..."** at the bottom of the menu. Selecting this will insert a "Custom Formula" chip into your text box. Follow these steps to use the formula:

1. **Click on the "Custom Formula" chip** to open the formula editor.
2. In the editor, you can type any number along with the following operators:
   * `+` for addition
   * `-` for subtraction
   * `/` for division
   * `*` or `x` for multiplication
   * `( )` for parentheses to group parts of the formula
3. **Insert Magic Numbers**:
   * Click the **Magic Number icon** to insert a number from your database.<img src="https://3467607506-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LhGHkPsv15svPIU5I7C%2Fuploads%2FiAOpBz2b0oynB08EXNSv%2Fimage.png?alt=media&#x26;token=9ab7c770-d8f2-4747-8edc-ace5cb4ff26f" alt="" data-size="line">
   * Magic Numbers use Number properties from your data, and you can filter them by [**Counts**, **Sums**, **Averages**,](https://help.adalo.com/component-basics/inserting-dynamic-text/connecting-your-database-for-counts-and-aggregating) etc., of related collections.
4. **Insert Functions**:
   * The Magic Number icon also allows you to insert functions into your formulas. The following functions are supported:

**Supported Functions**

* **Round**: Rounds a number to the nearest integer.

  ```plaintext
  ROUND(4.32) → 4
  ROUND(4.5) → 5
  ```
* **Integer (INT)**: Removes the decimals from a number (rounding down).

  ```plaintext
  INT(4.32) → 4
  INT(4.999) → 4
  ```
* **Absolute Value (ABS)**: Displays the absolute (positive) value of a number.

  ```plaintext
  ABS(-4.32) → 4.32
  ```
* **Square Root (SQRT)**: Displays the square root of a number.

  ```plaintext
  SQRT(9) → 3
  ```
* **Exponent (EXP)**: Raises one number to the power of another.

  ```plaintext
  EXP(3, 2) → 9 (which is 3²)
  ```
* **Random Number (RAND)**: Generates a random number between two specified values.

  ```plaintext
  RAND(0, 1) → A random number between 0 and 1
  ```
* **Logarithm (LOG)**: Displays the base 10 logarithm of a number.

  ```plaintext
  LOG(100) → 2
  ```

***

#### **Example: Calculating Trip Cost Per Person**

Let’s say you want to calculate the cost of a trip per person using a custom math formula.

1. Insert a text box.
2. Select the **Magic Text** button (red accented letter).
3. Choose **"New Formula"** from the popup menu.
4. Click on the **pencil icon** to open the formula editor.
5. Click the **Magic Number icon** and select **Trip Cost**.
6. Enter `/` (to divide).
7. Click the **Magic Number icon** again and select **Group Size**.
8. You can also[ edit prefixes, suffixes, and formatting for custom formulas ](https://help.adalo.com/component-basics/inserting-dynamic-text/how-to-format-dates-and-numbers)as needed.

<figure><img src="https://3467607506-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F-LhGHkPsv15svPIU5I7C%2Fuploads%2FWIfsQgYlW92T1PUiUojm%2Fimage.gif?alt=media&#x26;token=26c7470f-ace2-45e0-9fbd-a384b260f5bd" alt=""><figcaption></figcaption></figure>

Now, your formula will divide the total trip cost by the group size.&#x20;

### **Additional Tips**

* You can combine multiple Magic Numbers, operators, and functions in the same formula to create more complex calculations.
* Custom formulas are flexible—tailor them to your specific needs by adjusting the numbers or properties from your database. Check out some used by our Adalo Makers [Here](https://help.adalo.com/component-basics/inserting-dynamic-text/how-to-create-a-custom-math-formula/complex-calculations).
* Formulas using Dates will fail if MagicText is Null.&#x20;

## Help

If you need additional help with this article, you can always ask in our [community forum](https://forum.adalo.com/)! Be sure to paste the link to this article in your post as well!
