Skip to content

Commit

Permalink
GITBOOK-15: change request with no subject merged in GitBook
Browse files Browse the repository at this point in the history
  • Loading branch information
tea-artist authored and gitbook-bot committed Feb 21, 2024
1 parent 2e06f7f commit 125b570
Show file tree
Hide file tree
Showing 5 changed files with 139 additions and 0 deletions.
4 changes: 4 additions & 0 deletions SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@
* [Date](product/fields/field-type/date.md)
* [Checkbox](product/fields/field-type/checkbox.md)
* [Rating](product/fields/field-type/rating.md)
* [Link](product/fields/field-type/link.md)
* [Formula](product/fields/field-type/formula/README.md)
* [Syntax](product/fields/field-type/formula/syntax.md)
* [Functions reference](product/fields/field-type/formula/functions-reference.md)
* [Formatting](product/fields/formatting.md)
* [Show as](product/fields/show-as.md)
* [Single or multi value (advanced)](product/fields/single-or-multi-value-advanced.md)
Expand Down
80 changes: 80 additions & 0 deletions product/fields/field-type/formula/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Formula

Formula fields play a crucial role in app development, enabling dynamic computations within fields to enhance both interactivity and intelligence. This guide aims to demystify the basics of formula fields, equipping you with the know-how to effectively utilize them in your applications.

#### Fundamentals of Formula Fields

Formula fields allow you to perform calculations based on the values of other fields. These calculations range from simple mathematical operations to more complex string manipulations and logical evaluations.

**Data Types and Formulas**

Understanding data types is essential before crafting your formulas. Different data types support various operations and functions. Key data types include:

* **Numbers**: Integer or decimal, supporting basic arithmetic operations.
* **Text**: String values, enabling concatenation and certain text manipulations.
* **Dates**: Dates in specific formats, allowing for calculations based on time.
* **Booleans**: True (TRUE) or false (FALSE), for logical operations.

**Field References**

In formulas, field values can be referenced by their names. Ensure accuracy in field names, remembering their case sensitivity.

#### Best Practices in Formula Writing

Creating formulas involves operators, functions, and field references. Here are some practical tips:

**Using Operators**

* **Addition** (`+`): Calculates sums or concatenates strings.
* **Subtraction** (`-`): Finds the difference between numbers.
* **Multiplication** (`*`): Multiplies numbers.
* **Division** (`/`): Divides numbers.
* **Modulus** (`%`): Calculates the remainder of the division.

**Applying Functions**

Functions are predefined formulas performing specific operations. For example, the `SUM` function totals multiple values, while the `LEFT` function extracts a number of characters from a text field.

**Text Manipulation**

When dealing with text, you might need to:

* **Concatenate**: Use `&` or the `CONCATENATE` function to join text strings.
* **Substring**: Extract parts of a string with `LEFT`, `RIGHT`, or `MID`.

**Logical Evaluations**

The `IF` function allows for conditional logic, returning different values based on a condition:

```plaintext
IF(condition, value_if_true, value_if_false)
```

**Complex Expressions**

You may craft expressions involving multiple operations and functions. Use parentheses wisely to manage the order of operations.

#### Formatting and Interactive Display

The results of formulas can also be formatted and configured for interactive displays, tailoring output to custom display needs. Given the dynamic nature of formula outputs, formatting and interactive display options depend on the inferred results of specific expressions.

> The value type of a formula field is deduced statically when entering the formula, not during actual computation with referenced values. Thus, formatting and interactive display configurations are available immediately after formula input.
### Debugging and Optimization

A correctly written formula should execute without errors, yielding expected results. If a formula isn't working as anticipated, debugging may be necessary.

#### Debugging Tips

* **Check Data Types**: Ensure operations and functions are applied to appropriate data types.
* **Verify Field References**: Confirm the accuracy of referenced field names.
* **Step-by-Step Verification**: Break down complex formulas into smaller parts for individual testing.

#### Performance Considerations

* **Avoid Redundant Calculations**: Store repeated calculations in a separate field if they're used in multiple places.
* **Limit Complex Functions**: Functions involving extensive data manipulation can impact performance.

### Conclusion

Mastering formula fields is key to enhancing your app development skills. Thoughtfully designed formulas can significantly improve both efficiency and user experience. Focus on accuracy, readability, and performance when writing formulas. With practice, you'll become adept at using formulas to meet complex business needs.
3 changes: 3 additions & 0 deletions product/fields/field-type/formula/functions-reference.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Functions reference

##
50 changes: 50 additions & 0 deletions product/fields/field-type/formula/syntax.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# Syntax

#### Basic Elements

Our formula syntax includes several basic elements:

* **Strings**: Text enclosed in either single or double quotes, such as 'Hello' or "World".
* **Numbers**:
* **Integers**: Pure numerical values like 123 or -456.
* **Decimals**: Numbers with a decimal point, like 12.34 or -45.67.
* **Boolean values**: Representing true or false with `TRUE` and `FALSE`.
* **Field references**: Used to refer to the value of a specific field. They can be used directly with the identifier name or enclosed in braces, such as `{age}`.

#### Operators

Operators in formulas are used to connect or compare values:

* **Mathematical operations**:
* Addition (+)
* Subtraction (-)
* Multiplication (\*)
* Division (/)
* Modulus (%)
* **Comparison operations**:
* Greater than (>)
* Less than (<)
* Greater than or equal to (>=)
* Less than or equal to (<=)
* Equal to (=)
* Not equal to (!=)
* **Logical operations**:
* Logical AND (&&)
* Logical OR (||)
* Bitwise AND (&)

#### Function Calls

You can call functions within your formulas. A function call consists of the function name, a pair of parentheses, and arguments inside the parentheses separated by commas.

For example: `sum(1, 2, 3)` calls a function named `sum` and passes three arguments to it: 1, 2, and 3.

#### Other Structures

1. **Parentheses**: You can use parentheses to alter the precedence of operations, e.g., `(1 + 2) * 3`.
2. **Comments**: To enhance readability or provide additional context for other users, you can include comments in your formulas. Block comments are enclosed with `/*` and `*/`, while line comments start with `//`.
3. **Whitespace and spaces**: Whitespace, newlines, and comments are generally ignored in formulas, but they can help improve the readability of your formulas.

#### Summary

You should now have a basic understanding of our formula syntax. Remember, the core purpose of formulas is to assist with data manipulation and calculations. By utilizing the basic elements, operators, and other structures mentioned above, you can construct a wide variety of formulas to meet your needs.
2 changes: 2 additions & 0 deletions product/fields/field-type/link.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Link

0 comments on commit 125b570

Please sign in to comment.