[[["易于理解","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-04。"],[],[],null,["CAST\n====\n\nConverts a field or expression from one type to another type.\n\nSample usage\n------------\n\n- `CAST(Number_field AS TEXT)`\n- `CAST(Text_field AS NUMBER)`\n- `CAST(Date_field as DATETIME)`\n\nSyntax\n------\n\n```\nCAST field_expression AS type\n```\n\n### Parameters\n\n- \u003cvar translate=\"no\"\u003efield_expression\u003c/var\u003e - a field or expression.\n\n- \u003cvar translate=\"no\"\u003etype\u003c/var\u003e - a data type literal.\n\n### `CAST` data type literals\n\nYou can cast from or to the following types:\n\nExamples\n--------\n\n**Goal** : Count website sessions longer than *N* seconds.\n\nIn a Google Analytics data source, **Session Duration** is a text dimension. The first step to counting sessions longer than *N* is to convert this to a number using `CAST`. The second step is to use the `CASE` statement to identify sessions longer than a certain value---we'll say 60 seconds for this example. We'll combine `CASE` with `SUM` to do the counting.\n\n**Step 1** : Create a new calculated field **Session Duration (number)** with the following formula:\n\n`CAST(Session Duration AS NUMBER)`\n\n**Step 2** : Create a new calculated field **Long Sessions** *:*\n\n`SUM(CASE WHEN Session Duration \u003e 60 THEN 1 ELSE 0 END)`\n\nNotes\n-----\n\nYou cannot `CAST` aggregated fields.\n\n- Casts from `[DATE|DATETIME]` to `TEXT` return the canonical string formats shown following. To return a different format, use the `FORMAT_DATETIME` function.\n- Casts from `TEXT` to `[DATE|DATETIME]` accept only the canonical string format. To parse a different format, use the `PARSE_*` functions.\n\n### Coercion to text\n\nWhen an expression requires a text string, Looker Studio coerces (implicitly converts) non-string values to a string data type.\n\nFor example, suppose we have a `created_datetime` field of type DATETIME and the following formula: \n\n```\nCONCAT(\"Created on \", created_datetime)\n```\n\nThis formula returns the following: \n\n```\nCreated on 2019-11-22 16:30:00.739182\n```\n\nThis formula doesn't require an explicit `CAST(created_datetime AS TEXT)`.\n\nRelated resources\n-----------------\n\n- [Dates and times](/looker/docs/studio/dates-and-times)\n- [Calculated fields](/looker/docs/studio/about-calculated-fields)\n- [Looker Studio function list](/looker/docs/studio/function-list)\n- [CASE expression](/looker/docs/studio/case-searched)"]]