Starting in Looker 21.12, you can use Quick Calculations to perform common calculations on numeric fields that are in an Explore's data table without using Looker functions and operators when the Custom Fields Labs feature is enabled, and you have permission to use them.
It's valuable to call out rows that meet (or do not meet) certain conditions in some reports. This pattern is often referred to as conditional formatting in Excel or other spreadsheet applications.
Looker supports conditional formatting in visualizations in several different ways:
- With the
html
LookML parameter. This is ideal for formatting values when the conditions driving the formatting are consistent across analysis for a given field. - With Table calculations. This approach ideal when the conditions driving the formatting need to be assignable from Looker's Explore UI.
- Directly in the visualization settings for table charts.
The second approach, leveraging table calculations for conditional formatting, is detailed in this article, with two examples using emojis.
Note: Not all backend databases support emojis in table calculations. These may unexpectedly break if your instance is migrated to a MySQL backend. Consider using conditional formatting for table charts from the visualization settings editor in an Explore, or implementing the conditional formatting using HTML instead.
Example 1:
In the example below, we created a calculation that uses the if
function to create the condition we would like to format for based on inventory_items.count
values, and the concat
function to prepend an emoji character depending on whether values satisfy the condition or not. The measure column is hidden from the visualization, so only the table calculation column with the conditionally prepended emoji is visualized.
The table calculation:
The resulting table and visualization (with inventory_items.count
hidden):
Example 2:
Similarly, this conditional formatting pattern could be applied to a percent change table calculation to call attention to rows that may warrant additional attention. In the example below, we have two calculations. The first returns the percent change (using the offset
function to compare values associated with different dates in the same column). The second applies the if
condition and concat
function to prepend a red icon to days where inventory_items.count
has negative growth as compared to the day before. This is similar to the table calculation created in the previous example.
The table calculation:
The resulting table and visualization:
To enable emojis:
- On a Mac:
CTRL + CMD + SPACE
brings up the emoji keyboard that allows you to select emojis to drop into a table calculation. - On a Windows machine: This article goes over how to enable and use emojis.