Chuyển đến nội dung chính

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.

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.

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, the SUM 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 or CONCATENATE function to join two or more text strings.
  • Substrings: Use LEFT, RIGHT, or MID functions to extract parts of strings.

Logical Evaluation

Use the IF function for logical evaluation to return different values based on conditions. The format is:
IF(điều_kiện, giá_trị_nếu_đúng, giá_trị_nếu_sai)

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àmMô tảĐầu vàoĐầu raVí dụ
SUMTính tổng các số, tương đương số_1 + số_2 + …số_1, [số_2, …]SốSUM(100, 200, 300)600
AVERAGETính giá trị trung bình của các sốsố_1, [số_2, …]SốAVERAGE(100, 200, 300)200
MAXTrả về số lớn nhất trong danh sáchsố_1, [số_2, …]SốMAX(100, 200, 300)300
MINTrả về số nhỏ nhất trong danh sáchsố_1, [số_2, …]SốMIN(100, 200, 300)100
ROUNDLàm tròn số đến một số chữ số thập phân nhất địnhsố, [độ_chính_xác]SốROUND(1.99, 0)2
ROUND(16.8, -1)20
ROUNDUPLàm tròn theo hướng đẩy giá trị ra xa số 0số, [độ_chính_xác]SốROUNDUP(1.1, 0)2
ROUNDUP(-1.1, 0)-2
ROUNDDOWNLàm tròn theo hướng đẩy giá trị tiến về số 0số, [độ_chính_xác]SốROUNDDOWN(1.9, 0)
2
ROUNDDOWN(-1.9, 0)-1
CEILINGsố, [bội_số]SốCEILING(2.49)3
CEILING(2.49, 1)2.4
FLOORsố, [bội_số]SốFLOOR(2.49)2
FLOOR(2.49, 1)2.4
EVENTrả về số chẵn nhỏ nhất mà lớn hơn hoặc bằng số đã choSốSốEVEN(0.1)2
EVEN(-0.1)-2
ODDTrả về số lẻ gần nhất với số đã choSốSốODD(0.1)1
ODD(-0.1)-1
INTTrả về phần nguyên của số đã choSốSốINT(1.9)1
INT(-1.9)-2
ABSTrả về giá trị tuyệt đối của số đã choSốSốABS(-1)1
SQRTTính căn bậc hai của một số không âmSốSốSQRT(4)2
POWERcơ_số, số_mũSốPOWER(2, 2)4
EXPSốSốEXP(0)1
EXP(1)2.718
LOGsố_dương, [cơ_số=10]SốLOG(100)2LOG(1024, 2)10
MODTrả về số dư của phép chiasố, số_chiaSốMOD(9, 2)1
MOD(9, 3)0
VALUEChuyển đổi văn bản thành sốVăn bảnSốVALUE(“$1,000,000”)1000000

Hàm xử lý văn bản

Tên hàmMô tảĐầu vàoĐầu raVí dụ
CONCATENATECONCATENATE(“Hello ”, “Sheets.vn”)Hello Sheets.vn
FINDFIND(“Sheets.vn”, “Hello Sheets.vn”)7
SEARCHSEARCH(“Sheets.vn”, “Hello Sheets.vn”)7
MIDMID(“Hello Sheets.vn”, 6, 6)Sheets
LEFTLEFT(“2023-09-06”, 4)“2023”
RIGHTRIGHT(“2023-09-06”, 5)“09-06”
REPLACEREPLACE(“Hello Sheets”, 7, 6, “Sheets.vn”)“Hello Sheets.vn”
REGEXP_REPLACEREGEXP_REPLACE(“Hello Sheest.vn”, “H.* ”, "")“Sheets.vn”
SUBSTITUTESUBSTITUTE(“Hello Sheets”, “Sheets”, “Sheets.vn”)“Hello Sheets.vn”
LOWERLOWER(“Hello Sheets.vn”)“hello sheets.vn”
UPPERUPPER(“Hello Sheets.vn”)“HELLO SHEETS.VN”
REPTREPT(“Hello!”, 3)“Hello!Hello!Hello!”
TRIMTRIM(” Hello ”)“Hello”
LENLEN(“Hello”)5
TT(“Hello”)“Hello”
T(100)null
ENCODE_URL_COMPONENTENCODE_URL_COMPONENT(“Hello Sheest.vn”)“Hello%20Sheets.vn”

Hàm xử lý logic

Tên hàmMô tảĐầu vàoĐầu raVí dụ
IFđiều_kiện, giá_trị_nếu_đúng, giá_trị_nếu_saiIF(2 > 1, “A”, “B”)“A”
IF(2 < 1, TRUE, FALSE)FALSE
SWITCHSWITCH(“B”, “A”, “Value A”, “B”, “Value B”, “Default Value”)“Value B”
ANDAND(1 < 2, 5 > 3)true
AND(1 < 2, 5 < 3)false
OROR(1 < 2, 5 < 3)true
OR(1 > 2, 5 < 3)false
XORXOR(1 < 2, 5 < 3, 8 < 10)false
XOR(1 > 2, 5 < 3, 8 < 10)true
NOTNOT(1 < 2)false
NOT(1 > 2)true
BLANKIF(2 > 3, “Yes”, BLANK())null
ERRORIF(2 > 3, “Yes”, ERROR(“Calculation”))“#ERROR: Calculation”
IS_ERRORIS_ERROR(ERROR())true

Hàm xử lý thời gian

Tên hàmMô tảĐầu vàoĐầu raVí dụ
TODAYTODAY()“2026-05-04 00:00”
NOWNOW()“2026-05-04 14:47”
YEARYEAR(“2023-09-08”)2023
MONTHMONTH(“2023-09-08”)9
WEEKNUMWEEKNUM(“2023-09-08”)36
WEEKDAYWEEKDAY(“2023-09-08”, “Monday”)5
DAYDAY(“2023-09-08”)8
HOURHOUR(“2023-09-08 16:50”)16
MINUTEMINUTE(“2023-09-08 16:50”)50
SECONDSECOND(“2023-09-08 16:50:30”)30
FROMNOWFROMNOW(, “day”)25
TONOWTONOW(, “day”)25
DATETIME_DIFFDATETIME_DIFF(“2022-08-01”, “2023-09-08”, “day”)403
WORKDAYWORKDAY(“2023-09-08”, 200)“2024-06-14 00:00:00”
WORKDAY_DIFFWORKDAY_DIFF(“2023-06-18”, “2023-10-01”)75
IS_SAMEIS_SAME(“2023-09-08”, “2023-09-10”)false
IS_AFTERIS_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àmMô tảĐầu vàoĐầu raVí dụ
COUNTALLgiá_trị_1, [giá_trị_2, …]SốCOUNTALL(100, 200, "", “Sheets.vn”, TRUE())5
COUNTAgiá_trị_1, [giá_trị_2, …]SốCOUNTA(100, 200, 300, "", “Sheets.vn”, TRUE)4
COUNTgiá_trị_1, [giá_trị_2, …]SốCOUNT(100, 200, 300, "", “Sheets.vn”, TRUE)3
ARRAY_JOINchuỗi, [ký_tự_ngăn_cách]Văn bảnARRAY_JOIN([“Tom”, “Jerry”, “Mike”], ”; ”)“Tom; Jerry; Mike”
ARRAY_UNIQUEChuỗiChuỗiARRAY_UNIQUE([1, 2, 3, 2, 1])[1, 2, 3]
ARRAY_FLATTENChuỗiChuỗiARRAY_FLATTEN([1, 2, ” ”, 3, true], [“ABC”])[1, 2, 3, ” ”, true, “ABC”]
ARRAY_COMPACTChuỗiChuỗiARRAY_COMPACT([1, 2, 3, "", null, “ABC”])[1, 2, 3, “ABC”]

Các hàm khác

Tên hàmMô tảĐầu vàoĐầu raVí dụ
RECORD_IDTrả về ID của bản ghi-Văn bảnRECORD_ID()recxxxxxx