By using HTML tags in LookML, it is possible to manipulate certain elements of table visualizations, such as font color or size. Using HTML tags and Liquid variables, you can build a dimension or measure with the style of your choice. Read about the html
field parameter and Liquid variables on the html
and Liquid variables documentation pages, respectively.
For example, this dimension will display names in green:
dimension: name {
type: string
sql: ${TABLE}.name ;;
html: <font color="green">{{ value }}</font>;;
}
This can be helpful for highlighting specific values or conditions with conditional formatting. There is also an option for conditional formatting on the Formatting tab for table visualizations. To apply conditional formatting in your visualization, turn on the Enable Conditional Formatting feature to view the options. You can specify the color code for your visualization in the Rule section. If you have more than one rule, the rules higher on the list have precedence over rules lower on the list. In the Format box, choose whether to color-code values along a scale or based on a logical condition (as shown on the Enable Conditional Formatting documentation page).
If you are color-coding values on a scale, you will choose your color palette in the Palette box — you can choose one of several existing palettes, or you can create a custom palette. If you are color-coding values based on a logical condition, choose the Background Color, Font Color, and Font Style for values that meet the condition. You can also choose whether to apply a rule to all numeric fields in the visualization, or apply the rule to just one or to more fields using the Apply to box.
Liquid HTML
Additionally, we can use Liquid HTML in the
html
parameter of your LookML to conditionally format dimensions or measures. For example, a measure in LookML called
spend
gives the amount spent per user, and we would like to change the font color and size based on the spend amount.
In LookML, the conditions for the formatting will look like this:
measure: spend {
type: sum
html:
{% if value > 100 %}
<p style="color: red; font-size: 50%">{{ rendered_value }}</p>
{% elsif value >1000 %}
<p style="color: blue; font-size:80%">{{ rendered_value }}</p>
{% else %}
<p style="color: black; font-size:100%">{{ rendered_value }}</p>
{% endif %};;
}