CASE WHEN REGEXP_MATCH(CAMPAIGN, "C.*")THEN"Consumer" WHEN REGEXP_MATCH(CAMPAIGN, "E.*")THEN"Electronics" WHEN REGEXP_MATCH(CAMPAIGN, "S.*")THEN"Social" ELSE"Misc" END
[[["易于理解","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-07-31。"],[],[],null,["# Use functions in calculated fields\n\nFunctions let you manipulate your data in ways beyond doing simple arithmetic. Looker Studio provides over 50 functions, grouped into the following types:\n\n- **Aggregation** functions perform calculations over multiple rows of your data. Examples include SUM, AVG, MIN, MAX.\n- **Arithmetic** functions apply mathematical calculations to your data. Examples include LOG, POWER, ROUND.\n- **Date** functions let you manipulate and transform time data. Examples include DATE, DATETIME_DIFF, YEAR.\n- **Geo** functions let you transform geographic location data. Examples include TOCITY, TOCOUNTRY, TOREGION.\n- **Text** functions let you manipulate string data. Examples include CONCAT, REGEXP_MATCH, SUBSTR.\n\n[See the complete list of available functions](/looker/docs/studio/function-list).\n\nFunction arguments\n------------------\n\nAll functions expect input, called *arguments,* that tell the function what data to act upon. Arguments can be field names or *expressions*. An expression can be a number, literal text, or a statement that evaluates to a field name in your data source. Arguments can also provide additional instructions or formatting information.\n\n### More about function arguments\n\n- When providing function arguments, be sure to enclose literal text in single or double quotes.\n- When using regular expressions, use double backslash to escape special characters. For example: `REGEXP_MATCH(GotStars, \"\\\\*\")` Matches the literal \\* character.\n- Geo functions require a supported geo code as input.\n\nGeo input codes\n---------------\n\n- ' CITY_ID '\n- ' CONTINENT_CODE '\n- ' COUNTRY_ISO_CODE '\n- ' REGION_ISO_CODE '\n- ' SUB_CONTINENT_CODE '\n\nThe valid geo codes are defined here:\n\n- [Country/Region codes](https://en.wikipedia.org/wiki/ISO-3166-2)\n- [City ID](https://developers.google.com/adwords/api/docs/appendix/geotargeting)\n- [Continent and Subcontinent codes](https://en.wikipedia.org/wiki/UN_M49)\n\n\u003e The input code is optional if the field expression is a derived column already containing semantic geo information; otherwise it is required.\n\nFunction examples\n-----------------\n\nHere are some simple examples of using the most popular functions. Additional complex examples are available in the individual [function references](/looker/docs/studio/function-list).\n\n### Example 1: Organize and simplify your Analytics campaigns.\n\nSuppose you run multiple ad campaigns, and use a coding system to identify them by category. Assuming the codes share a regular format, you could use the CASE expression and REGEXP_MATCH function to group related campaigns.\n\nFor example, say you've got campaign codes like C1, C2, and C3 for consumer goods, E1, E2, and E3 for electronics, S1, S2, and S3 for social ads. You could group these campaign codes into their respective category, and optionally, lump other campaigns into a miscellaneous category:\n\n`CASE` \n\n`WHEN REGEXP_MATCH``(CAMPAIGN, \"C.*\")``THEN``\"Consumer\"` \n\n`WHEN REGEXP_MATCH``(CAMPAIGN, \"E.*\")``THEN``\"Electronics\"` \n\n`WHEN REGEXP_MATCH``(CAMPAIGN, \"S.*\")``THEN``\"Social\"` \n\n`ELSE``\"Misc\"` \n\n`END`\n\nYou can now use this calculated field to see how your campaigns are performing per group, or use it in a [filter control](/looker/docs/studio/about-controls) to refine the view of your data.\n\n[Learn more about CASE](/looker/docs/studio/case-searched).\n\n### Example 2: Combine values from multiple fields.\n\nYou can aggregate and display your data in new ways by combining multiple fields via the CONCAT function. This creates a new field with the concatenated values. For example:\n\n`CONCAT``('Browser: ', BROWSER, ' Version: ', BROWSER VERSION)`\n\nThe new field will show the literal strings and dimension values as a single entry. The data values might look like the following examples:\n\n- Browser: Chrome Version: 68.0.3440.106\n- Browser: Safari Version: 11.0\n- Browser: Firefox Version: 61.0\n\n### Example 3. Create hyperlinks from your data\n\nIf your data contains URLs, you can create clickable links that appear in tables by using the HYPERLINK function.\n\nFor example, suppose you've got a custom SKU dimension associated with the URL to the relevant product description in the PAGE dimension. The following formula creates a clickable link for each record in your data:\n\n`HYPERLINK``(URL, SKU )`\n\nIf your data doesn't contain the complete URL, or you need to combine multiple fields to create the URL, use CONCAT to construct the link:\n\n`HYPERLINK(CONCAT``(\"HTTPS://mydomain.com/\", PARTIAL-URL, \"?some-parameter\"), SKU )`\n\nYou can also use the HYPERLINK function to create clickable images in your tables.\n\n[Learn more about HYPERLINK](/looker/docs/studio/hyperlink).\n\nLimits of calculated fields\n---------------------------\n\nFormulas in calculated fields can't mix unaggregated data (dimensions) and aggregated data (metrics).\n\nFor example, the following is **not** allowed: \n\n CASE WHEN Country = \"England\" AND Conversions \u003e 100 THEN... // invalid formula\n\nIn this example, Conversions is an aggregated metric.\n\nRelated resources\n-----------------\n\n- [Looker Studio function list](/looker/docs/studio/function-list)\n- [Dimensions and metrics](/looker/docs/studio/model-your-data)\n- [Create a data source](/looker/docs/studio/add-data-to-a-report)"]]