About Equations
What is an equation?
Equation fields function by merging field values, numbers, and other mathematical functions to construct an equation that will be calculated for each record. These fields are a specific type of field found in a table within the Data section of the Builder.
There are two equation types available: Number and Date
Numeric Equation example : (Sales - Expenses) * 12
Date Equation example : (Date Completed) - (Date Started)
Managing Equations
Adding an Equation
To add a field to a table in the Builder's Data section, start by selecting the desired table from the left menu. Next, click on the "Add Field" button located at the top of the page.
This will give you the option to choose the Equation field type from the left side of the screen:
After selecting the Equation field type, a popup will appear where you can customize the settings for your Equation field. Once you have configured the field, simply click on the "Add Field" button located at the bottom of the pop-up window.
Editing an Equation
To modify an existing equation, choose the table that includes the equation field and then select the additional options icon (represented by "...") located beside the field's name.
Deleting an Equation
To remove an equation, navigate to the table that contains the equation field and click on the additional options icon (represented by "...") next to the field's name. From the dropdown menu, select the "Delete" option.
Caution: Please note that deleting a field will result in the removal of all record values associated with that field. Therefore, it is important to confirm that this is the correct action for your app before proceeding.
Building an Equation
Equations can take many different forms. See the Equation Types section for details on these options.
To build to your equation:
-
Type the name of the field directly in the formula input box.
-
Use the "Fields" dropdown list to select any available fields, or
-
Type numbers or mathematical operators directly into the input box.
Below the equation editor, the Example Output shows you an example output of the current formula:
Accessing Connected Fields
As with text formulas, equations give you the option of retrieving data from connected records. If you start typing the name of a field on a connected table, you'll see the available options in a list.
You can also select the "Fields" dropdown and select the field. Fields available will include any fields from the data table you are currently in and any fields from connected tables.
Note: Fields from tables connected with a many-to-many relationship will not be available since multiple connected record values exist.
Tip: Check out our quick guide on how to include connected values in equations**:How to Include Connected Values in Equations**
Using Multiple Choice Fields in Equations
Multiple choice fields can be utilized in equations, whereby these values are automatically converted into numerical values for calculation purposes.
Non-numeric characters are automatically removed and the remaining value is considered for calculation. In case there is no number left, zero will be used as the default value.
Note: Equations using multiple choice fields will not display live results, even if the multiple choice field is used in the form.
Using Yes / No Fields in Equations
Yes/No fields can be utilized in equations. In these equations, the values of No and Yes are converted to numerical values, where No is represented as 0 and Yes is represented as 1, which are then used in the equation.
Using Equations in Forms
Requirements:
-
All fields required for the equation must be included on the form. Similarly, if you are setting a value in a record rule using a formula field, that field must also be present on the form.
-
The equation must be a Numeric equation and cannot be a Date Type.
-
The equation cannot use other formulas (sum , count , etc.)
Equation fields can be incorporated into forms to create dynamic calculators that update in real time. Let's take a look at a basic example:
Note: Currently, form submissions cannot be validated using equation fields.
Operators
You can use the following operators in your equations:
| Operator | Meaning |
|---|
- | adds
- | subtracts
- | multiples / | divides == | equals != | not equals
| greater than = | greater than or equal to 0 & Condition B > 10 ? Equation 1 : Equation 2
Note: Unfortunately, it is not feasible to evaluate whether a field "is blank" or "is not blank" within a conditional equation.
Conditional Example 1:
There may be times when you need to track total elapsed time. This could easily be done using the currentTime() function, but what happens when your date field is blank?
A blank date would be interpreted as "0", which Knack would interpret as "January 1, 1970", resulting in a very long negative number. Using a conditional rule we can make sure our equation remains "0" instead:
(Invoice Date) > 0 ? (Invoice Date) - currentTime() : 0
Conditional Example 2:
This example shows how to apply an additional 3% late fee to a charge:
(Time of Payment) > (Due Date) ? (Cost) * 1.03 : (Cost)
Conditional Example 3:
To trigger an equation when values are equal you can use the "==" operator:
(Budget Period) == 1 ? (Q1 Date) : (Budget Period)==2 ? (Q2 Date) : 0
Conditional Example 4
This complex example uses the following logic:
-
If
Time of Paymentis later thanDue Date, charge an extra 3% -
If
Time of Paymentis earlier than theDue Date, charge 1% less -
Otherwise (if
Time of PaymentequalsDue Date), charge the normal amount
(Time of Payment) > (Due Date) ? ((Cost) 1.03) : ((Time of Payment) 0 & (Start Date) > 0 ? (End Date) - (Start Date) : (Start Date) > 0 ? currentTime() - (Start Date) : 0
Conditional Equations with Text Fields
Conditional rules don’t currently work with text fields, but you can map your text fields to number fields and use the number fields in your equation. Assuming you already have a short text field called Text:
-
Add a number field (we’ll call it
Num). -
Add a conditional rule to the
Numfor each option you want to account forText; e.g. setNumto "1" ifTextis "First Choice", setNumto "2" ifTextis "Second Choice", etc. -
Run a batch update on your data (even on a new temporary field) to populate the
Numfield via its conditional rules. -
Use
Numin place ofTextin your equations.
Conditional Equation with Text Fields Example
If we want the following conditions tested:
-
If
Textis "First Choice", ie:Numis 1, set the equation to "1" -
If
Textis "Second Choice", ie:Numis 2 set equation to "2" -
If
Textis anything else, set the equation to "0"
In the equation, you would need to utilize the Num field since equations cannot use text fields. Therefore, the equation would be structured as follows:
(Num) ==1 ? 1 : (Num) ==2 ? 2 : 0
Using Equations in Your App
Use Equations in Equation or Text Formula Fields
Just as in any other field on a table connected to another table, equation fields can be used in text formulas or other equation fields.
Viewing Equations in the Builder
Equation values will be displayed in the "Records" tab in a table in the Builder. Here you can view and reference these values, as well as use record filters to display particular values for this equation field.
Viewing Equations in the Live App
Except for maps, menus, and rich text views, equation fields can be added and used to display values in all** page views.**
How To Guides
Troubleshooting
Can't Access Connected Field
If you're unable to access a connected field in a formula, check the connection between the two tables. You can only access fields from a table with a many-to-one or one-to-one relationship with the table you're adding the equation field to.
For example, let's say that many Tasks can be connected to one Project, and there's a number field called "Hourly Rate" in the Project table. You can create an equation in the Tasks table that pulls in the value from the Hourly Rate field in the Project's table because there's only one hourly rate value to pull in.
However, if you had a number field called "Hours Worked" in the Tasks table, you wouldn't be able to access that field in an equation in the Projects table. There would be multiple "Hours Worked" values to pull in and an equation field can't do that.
In a case like that, you could use a formula field to access all the connected "Hours Worked" values. Then, the formula field could be used in the equation.
Updated 18 days ago




