[[["易于理解","easyToUnderstand","thumb-up"],["解决了我的问题","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["很难理解","hardToUnderstand","thumb-down"],["信息或示例代码不正确","incorrectInformationOrSampleCode","thumb-down"],["没有我需要的信息/示例","missingTheInformationSamplesINeed","thumb-down"],["翻译问题","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["最后更新时间 (UTC):2025-09-03。"],[],[],null,["IF\n===\n\n`IF` defines a condition and returns a result when that condition is met, or returns a different result if that condition is not met.\n| **Note:** `IF` is similar to `CASE` but acts only on a single condition, and can return only one true result or one false result.\n\nSample usage\n------------\n\nCalculate a bonus rate if actual sales exceed forecast sales:\n\n`IF(Actual \u003e Forecast, Bonus *1.2, Bonus)`\n\nSyntax\n------\n\n`IF( `\u003cvar translate=\"no\"\u003econdition\u003c/var\u003e`, `\u003cvar translate=\"no\"\u003etrue_result\u003c/var\u003e`, `\u003cvar translate=\"no\"\u003efalse_result\u003c/var\u003e` )`\n\n### Parameters\n\n- \u003cvar translate=\"no\"\u003econdition\u003c/var\u003e - The expression to evaluate. \u003cvar translate=\"no\"\u003econdition\u003c/var\u003e can be any valid Boolean expression.\n- \u003cvar translate=\"no\"\u003etrue_result\u003c/var\u003e - the value to return if \u003cvar translate=\"no\"\u003econdition\u003c/var\u003e is true. \u003cvar translate=\"no\"\u003etrue_result\u003c/var\u003e can be any valid expression.\n- \u003cvar translate=\"no\"\u003efalse_result\u003c/var\u003e - the value to return if \u003cvar translate=\"no\"\u003econdition\u003c/var\u003e is false. \u003cvar translate=\"no\"\u003efalse_result\u003c/var\u003e can be any valid expression.\n\nExamples\n--------\n\nReturn a dimension based on a parameter selection.\n\nFor example, you can create a **Boolean** parameter, **Forecast Parameter**, and use it to return a column of forecasted data. Otherwise, use the actual data:\n\n`IF(Forecast Parameter, Forecast Data, Actual Data)`\n\nIdentify records that are older than a certain number of days before today:\n\n`IF(DATETIME_DIFF(TODAY(),Date,DAY) \u003e 60, \"old\",\"new\")`\n\nA more complex condition with logical `AND`, and regular expression matching:\n\n`IF(Event name = \"purchase\" AND (REGEXP_MATCH(Page path, \".*footwear.*\") OR REGEXP_MATCH(Page path, \".*shoes.*\")), \"Shoe Sales\", Page title)`\n| **Note:** `IF` is limited to returning only one of two possible results: the `true_result` or the `false_result`. To create a function that can return more possible results, use [`CASE`](/looker/docs/studio/case-searched) or [simple `CASE`](/looker/docs/studio/case-simple) instead.\n\nRelated resources\n-----------------\n\n- [About calculated fields](/looker/docs/studio/about-calculated-fields)\n- [Looker Studio function list](/looker/docs/studio/function-list)\n- [google/RE2 GitHub documentation](https://github.com/google/re2/wiki/Syntax)"]]