[[["易于理解","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-05。"],[],[],null,["# Conditional formatting using table calculations\n\n\u003e You can use [shortcut calculations](/looker/docs/table-calculations#quick_calculations) to perform common calculations on numeric fields that are in an Explore's data table without using Looker [functions and operators](/looker/docs/functions-and-operators) when you have the [permissions](/looker/docs/admin-panel-users-roles#create_table_calculations) to create table calculations.\n\n\nIt's valuable to call out rows that meet (or don't meet) certain conditions in some query results. This pattern is often referred to as *conditional formatting* in Google Sheets or other spreadsheet applications.\n\n\nLooker supports conditional formatting in visualizations in several different ways:\n\n- With the [`html`](/looker/docs/reference/param-field-html#using_liquid_variables_in_the_html_parameter) LookML parameter. This is ideal for formatting values when the conditions that drive the formatting are consistent across analysis for a given field.\n- With [table calculations.](/looker/docs/table-calculations#creating_table_calculations_in_looker) This approach is ideal when the conditions that determine the formatting need to be assignable from Looker's Explore UI.\n- Directly in the [visualization settings](/looker/docs/table-options#enable_conditional_formatting) for table charts.\n\n\nThe second approach, which leverages table calculations to determine conditional formatting, is detailed on this page with two examples that use emoji\n\n\nTo enable emoji:\n\n- For Mac: `CTRL + CMD + SPACE` brings up the emoji keyboard that lets you select emoji to drop into a table calculation.\n- For Windows: [This Buffer article about emoji keyboard shortcuts](https://blog.bufferapp.com/emojis-keyboard-shortcut-mac-windows) goes over how to enable and use emoji.\n\n\n**Note: Not all backend databases support emoji in table calculations.** Emoji may unexpectedly break if your instance is migrated to a MySQL backend. Consider using [conditional formatting for table charts](/looker/docs/table-options#enable_conditional_formatting) from the visualization settings editor in an Explore, or implementing the conditional formatting using [HTML](https://community.looker.com/technical-tips-tricks-1021/how-to-change-colors-and-fonts-using-html-30236) instead.\n\nExample 1\n---------\n\n\nThe following example is based on an Explore query with **Inventory Items Count** grouped by **Inventory Items Created Date** . A user wants to add an emoji to indicate whether a value of **Inventory Items Count** is greater than or less than a specified number.\n\n\nThe first step is to create a calculation that uses the [`if`](/looker/docs/functions-and-operators#logical_functions,_operators,_and_constants) function to specify a condition for categorizing **Inventory Items Count** values, and the [`concat`](/looker/docs/functions-and-operators#string_functions) function to prepend an emoji character depending on whether or not the values satisfy the condition.\n\n\nThe user wants to use emoji to indicate whether or not a value meets the condition. A green check mark emoji indicates a value that meets the condition, and a red **x** emoji indicates a value that does not meet the condition.\n\n\nThe table calculation is: \n\n```\nconcat(\n if(${inventory_items.count} \u003e 255, \"\u003cemoji\u003e\" ,\n if(${inventory_items.count} \u003c 260, \"\u003cdifferent_emoji\u003e\" , \" \")), \" \"\n ,${inventory_items.count})\n```\n\n\nHere the table calculation is shown with emoji in the **Create table calculation** menu or in the [**In-page Table Calculation editor**](/looker/docs/table-calculations#creating_and_editing_table_calculations_with_in-page_table_calculations) when the [**In-page Table Calculations** Labs feature](/looker/docs/admin-panel-general-labs#in-page_table_calculations) is enabled:\n\n\nThis table calculation produces the following table visualization:\n\n\nThe **Inventory Items Count** measure column is [hidden](/looker/docs/creating-visualizations#specifying_lookml_fields_to_include_in_the_visualization) from the visualization, so only the table calculation column with the conditionally prepended emoji is visualized.\n\nExample 2\n---------\n\n\nSimilarly, the Example 1 conditional formatting pattern can be applied to a percent change table calculation to call attention to rows that may warrant additional attention. The following example has two calculations. This example also uses the Explore with **Inventory Items Count** grouped by **Inventory Items Created Date**.\n\n\nThe first table calculation returns the percent change (using the [`offset`](/looker/docs/functions-and-operators#row-related_functions_for_table_calculations_only) function to compare values associated with different dates in the same column): \n\n```\n (${inventory_items.count} - offset(${inventory_items.count},\n -1))/offset(${inventory_items.count}, -1)\n```\n\n\nIn this example of an Explore, the table calculation is named **Inventory Items Count percentage change**, which is referenced in the second table calculation.\n\n\nThe second table calculation applies the `if` condition and `concat` function to prepend a red **x** emoji to days where **Inventory Items Count**has negative growth as compared to the day before: \n\n```\n concat(\n if((${inventory_items_count_percentage_change}*100) \u003c 0, \"\u003cemoji\u003e\", \" \"), \" \",\n round(${inventory_items_count_percentage_change}*100,1),\n if(is_null(${inventory_items_count_percentage_change}), \" \", \"%\"))\n```\n\n\nThese two table calculations produce an Explore data table with two new rows for the **Inventory Items Count percentage change** and **Inventory Items Count percent change** conditional value emoji table calculations. The resulting table visualization displays the results for all fields except **Inventory Items Count percentage change** . The **Inventory Items Count percentage change** table calculation is hidden from the table visualization:"]]