Formula fields allow you to perform calculations based on other field values. These calculations can be simple mathematical operations or complex string manipulations and logical evaluations.Documentation Index
Fetch the complete documentation index at: https://www.sheets.vn/docs/llms.txt
Use this file to discover all available pages before exploring further.
Data Types and Formulas
Before starting to write formulas, understanding data types is crucial for ensuring your formulas work correctly. Different data types support different operations and functions. Common data types include:- Numbers: Integers or decimals, supporting arithmetic operations.
- Text: String values, supporting concatenation and partial text operations.
- Dates: Specifically formatted dates, supporting date calculations.
- Boolean: True (TRUE) or false (FALSE), used for logical operations.
Referencing Fields
In formulas, you can reference other field values by their field names. Make sure to use the correct field names and note that field names are case-sensitive.Formula Writing Practices
When writing formulas, you’ll use operators, functions, and field references. Here are some practical formula writing practices:Using Operators
- Addition (
+): Used for calculating sums of numbers or concatenating strings. - Subtraction (
-): Used for calculating differences between numbers. - Multiplication (
*): Used for calculating products of numbers. - Division (
/): Used for calculating quotients of numbers. - Modulo (
%): Used for calculating remainders of numbers.
Applying Functions
Functions are predefined formulas that perform specific operations. For example, theSUM function can calculate the total of multiple values, while the LEFT function can extract a certain number of characters from a text field.
Handling Text
When working with text, you might need to use the following operations:- Concatenation: Use the
&operator orCONCATENATEfunction to join two or more text strings. - Substrings: Use
LEFT,RIGHT, orMIDfunctions to extract parts of strings.
Logical Evaluation
Use theIF function for logical evaluation to return different values based on conditions. The format is:
Complex Expressions
You may need to write complex expressions involving multiple operations and functions. In such cases, ensure you use proper parentheses to control the order of operations.Formatting and Interactive Display
Formula output results can also participate in formatting and interactive display configurations, allowing output content to meet custom display requirements. Since formula outputs are dynamic, the available formatting and interactive display configurations are determined by the inferred result of the specific expression.The field value type of a formula is statically inferred when entering the formula, without waiting for actual calculation with referenced values. Therefore, you can always select formatting and interactive display configurations immediately after entering the formula.
Debugging and Optimization
Once a formula is written correctly, it should execute without errors and return expected results. If a formula isn’t working as expected, you may need to debug it.Debugging Tips
- Check Data Types: Confirm that your operations and functions use the correct data types.
- Verify Field References: Ensure referenced field names are correct.
- Step-by-Step Testing: Break down complex formulas into smaller parts and test each part separately.
Performance Considerations
- Avoid Redundant Calculations: If the same calculation is used in multiple places, consider storing its result in a separate field.
- Limit Complex Functions: Some complex functions, such as those involving large data operations, may impact performance.
Tổng hợp các hàm
Hàm xử lý số
| Tên hàm | Mô tả | Đầu vào | Đầu ra | Ví dụ |
|---|---|---|---|---|
| SUM | Tính tổng các số, tương đương số_1 + số_2 + … | số_1, [số_2, …] | Số | SUM(100, 200, 300)⇒600 |
| AVERAGE | Tính giá trị trung bình của các số | số_1, [số_2, …] | Số | AVERAGE(100, 200, 300)⇒200 |
| MAX | Trả về số lớn nhất trong danh sách | số_1, [số_2, …] | Số | MAX(100, 200, 300)⇒300 |
| MIN | Trả về số nhỏ nhất trong danh sách | số_1, [số_2, …] | Số | MIN(100, 200, 300)⇒100 |
| ROUND | Làm tròn số đến một số chữ số thập phân nhất định | số, [độ_chính_xác] | Số | ROUND(1.99, 0) ⇒ 2 ROUND(16.8, -1)⇒20 |
| ROUNDUP | Làm tròn theo hướng đẩy giá trị ra xa số 0 | số, [độ_chính_xác] | Số | ROUNDUP(1.1, 0)⇒2 ROUNDUP(-1.1, 0)⇒-2 |
| ROUNDDOWN | Làm tròn theo hướng đẩy giá trị tiến về số 0 | số, [độ_chính_xác] | Số | ROUNDDOWN(1.9, 0)⇒ 2 ROUNDDOWN(-1.9, 0)⇒-1 |
| CEILING | số, [bội_số] | Số | CEILING(2.49)⇒3 CEILING(2.49, 1)⇒2.4 | |
| FLOOR | số, [bội_số] | Số | FLOOR(2.49)⇒2 FLOOR(2.49, 1)⇒2.4 | |
| EVEN | Trả về số chẵn nhỏ nhất mà lớn hơn hoặc bằng số đã cho | Số | Số | EVEN(0.1)⇒2 EVEN(-0.1)⇒-2 |
| ODD | Trả về số lẻ gần nhất với số đã cho | Số | Số | ODD(0.1)⇒1 ODD(-0.1)⇒-1 |
| INT | Trả về phần nguyên của số đã cho | Số | Số | INT(1.9)⇒1 INT(-1.9)⇒-2 |
| ABS | Trả về giá trị tuyệt đối của số đã cho | Số | Số | ABS(-1)⇒1 |
| SQRT | Tính căn bậc hai của một số không âm | Số | Số | SQRT(4)⇒2 |
| POWER | cơ_số, số_mũ | Số | POWER(2, 2)⇒4 | |
| EXP | Số | Số | EXP(0)⇒1 EXP(1)⇒2.718 | |
| LOG | số_dương, [cơ_số=10] | Số | LOG(100)⇒2LOG(1024, 2)⇒10 | |
| MOD | Trả về số dư của phép chia | số, số_chia | Số | MOD(9, 2)⇒1 MOD(9, 3)⇒0 |
| VALUE | Chuyển đổi văn bản thành số | Văn bản | Số | VALUE(“$1,000,000”)⇒1000000 |
Hàm xử lý văn bản
| Tên hàm | Mô tả | Đầu vào | Đầu ra | Ví dụ |
|---|---|---|---|---|
| CONCATENATE | CONCATENATE(“Hello ”, “Sheets.vn”)⇒Hello Sheets.vn | |||
| FIND | FIND(“Sheets.vn”, “Hello Sheets.vn”)⇒7 | |||
| SEARCH | SEARCH(“Sheets.vn”, “Hello Sheets.vn”)⇒7 | |||
| MID | MID(“Hello Sheets.vn”, 6, 6)⇒Sheets | |||
| LEFT | LEFT(“2023-09-06”, 4)⇒“2023” | |||
| RIGHT | RIGHT(“2023-09-06”, 5)⇒“09-06” | |||
| REPLACE | REPLACE(“Hello Sheets”, 7, 6, “Sheets.vn”)⇒“Hello Sheets.vn” | |||
| REGEXP_REPLACE | REGEXP_REPLACE(“Hello Sheest.vn”, “H.* ”, "")⇒“Sheets.vn” | |||
| SUBSTITUTE | SUBSTITUTE(“Hello Sheets”, “Sheets”, “Sheets.vn”)⇒“Hello Sheets.vn” | |||
| LOWER | LOWER(“Hello Sheets.vn”)⇒“hello sheets.vn” | |||
| UPPER | UPPER(“Hello Sheets.vn”)⇒“HELLO SHEETS.VN” | |||
| REPT | REPT(“Hello!”, 3)⇒“Hello!Hello!Hello!” | |||
| TRIM | TRIM(” Hello ”)⇒“Hello” | |||
| LEN | LEN(“Hello”)⇒5 | |||
| T | T(“Hello”)⇒“Hello” T(100)⇒null | |||
| ENCODE_URL_COMPONENT | ENCODE_URL_COMPONENT(“Hello Sheest.vn”)⇒“Hello%20Sheets.vn” |
Hàm xử lý logic
| Tên hàm | Mô tả | Đầu vào | Đầu ra | Ví dụ |
|---|---|---|---|---|
| IF | điều_kiện, giá_trị_nếu_đúng, giá_trị_nếu_sai | IF(2 > 1, “A”, “B”)⇒“A” IF(2 < 1, TRUE, FALSE)⇒FALSE | ||
| SWITCH | SWITCH(“B”, “A”, “Value A”, “B”, “Value B”, “Default Value”)⇒“Value B” | |||
| AND | AND(1 < 2, 5 > 3)⇒true AND(1 < 2, 5 < 3)⇒false | |||
| OR | OR(1 < 2, 5 < 3)⇒true OR(1 > 2, 5 < 3)⇒false | |||
| XOR | XOR(1 < 2, 5 < 3, 8 < 10)⇒false XOR(1 > 2, 5 < 3, 8 < 10)⇒true | |||
| NOT | NOT(1 < 2)⇒false NOT(1 > 2)⇒true | |||
| BLANK | IF(2 > 3, “Yes”, BLANK())⇒null | |||
| ERROR | IF(2 > 3, “Yes”, ERROR(“Calculation”))⇒“#ERROR: Calculation” | |||
| IS_ERROR | IS_ERROR(ERROR())⇒true |
Hàm xử lý thời gian
| Tên hàm | Mô tả | Đầu vào | Đầu ra | Ví dụ |
|---|---|---|---|---|
| TODAY | TODAY()⇒“2026-05-04 00:00” | |||
| NOW | NOW()⇒“2026-05-04 14:47” | |||
| YEAR | YEAR(“2023-09-08”)⇒2023 | |||
| MONTH | MONTH(“2023-09-08”)⇒9 | |||
| WEEKNUM | WEEKNUM(“2023-09-08”)⇒36 | |||
| WEEKDAY | WEEKDAY(“2023-09-08”, “Monday”)⇒5 | |||
| DAY | DAY(“2023-09-08”)⇒8 | |||
| HOUR | HOUR(“2023-09-08 16:50”)⇒16 | |||
| MINUTE | MINUTE(“2023-09-08 16:50”)⇒50 | |||
| SECOND | SECOND(“2023-09-08 16:50:30”)⇒30 | |||
| FROMNOW | FROMNOW(, “day”)⇒25 | |||
| TONOW | TONOW(, “day”)⇒25 | |||
| DATETIME_DIFF | DATETIME_DIFF(“2022-08-01”, “2023-09-08”, “day”)⇒403 | |||
| WORKDAY | WORKDAY(“2023-09-08”, 200)⇒“2024-06-14 00:00:00” | |||
| WORKDAY_DIFF | WORKDAY_DIFF(“2023-06-18”, “2023-10-01”)⇒75 | |||
| IS_SAME | IS_SAME(“2023-09-08”, “2023-09-10”)⇒false | |||
| IS_AFTER | IS_AFTER(“2023-09-10”, “2023-09-08”)⇒true IS_AFTER(“2023-09-10”, “2023-09-08”, “month”)⇒false |
Hàm xử lý chuỗi
| Tên hàm | Mô tả | Đầu vào | Đầu ra | Ví dụ |
|---|---|---|---|---|
| COUNTALL | giá_trị_1, [giá_trị_2, …] | Số | COUNTALL(100, 200, "", “Sheets.vn”, TRUE())⇒5 | |
| COUNTA | giá_trị_1, [giá_trị_2, …] | Số | COUNTA(100, 200, 300, "", “Sheets.vn”, TRUE)⇒4 | |
| COUNT | giá_trị_1, [giá_trị_2, …] | Số | COUNT(100, 200, 300, "", “Sheets.vn”, TRUE)⇒3 | |
| ARRAY_JOIN | chuỗi, [ký_tự_ngăn_cách] | Văn bản | ARRAY_JOIN([“Tom”, “Jerry”, “Mike”], ”; ”)⇒“Tom; Jerry; Mike” | |
| ARRAY_UNIQUE | Chuỗi | Chuỗi | ARRAY_UNIQUE([1, 2, 3, 2, 1])⇒[1, 2, 3] | |
| ARRAY_FLATTEN | Chuỗi | Chuỗi | ARRAY_FLATTEN([1, 2, ” ”, 3, true], [“ABC”])⇒[1, 2, 3, ” ”, true, “ABC”] | |
| ARRAY_COMPACT | Chuỗi | Chuỗi | ARRAY_COMPACT([1, 2, 3, "", null, “ABC”])⇒[1, 2, 3, “ABC”] |
Các hàm khác
| Tên hàm | Mô tả | Đầu vào | Đầu ra | Ví dụ |
|---|---|---|---|---|
| RECORD_ID | Trả về ID của bản ghi | - | Văn bản | RECORD_ID()⇒recxxxxxx |