IF Function
Tests a condition and returns one value if TRUE and another if FALSE. The most fundamental decision-making function in spreadsheets.
ExcelGoogle Sheets
语法
IF(logical_test, value_if_true, [value_if_false])参数
| 参数名 | 说明 |
|---|---|
| logical_test | The condition to evaluate (e.g., A1>10). |
| value_if_true | The value returned when the condition is TRUE. |
| value_if_false(可选) | The value returned when the condition is FALSE. |
示例
Pass/Fail based on a score
=IF(A1>=60, "Pass", "Fail")结果: Pass (if A1 is 75)
Nested IF for letter grades
=IF(A1>=90, "A", IF(A1>=80, "B", IF(A1>=70, "C", "F")))结果: B (if A1 is 85)
Calculate bonus if sales target met
=IF(B2>=10000, B2*0.1, 0)结果: 1500 (if B2 is 15000)
技巧与最佳实践
- •Avoid deeply nested IFs — use IFS or SWITCH for multiple conditions.
- •If you omit value_if_false, the function returns FALSE when the test fails.
- •Combine with AND/OR for multi-condition tests: =IF(AND(A1>0, B1>0), "Both positive", "No").
- •Use IFERROR around formulas that might error, not IF(ISERROR(...)).
相关公式
需要其他公式?
用自然语言描述您的需求,AI 将为您生成公式。
试试公式生成器