Conditional Formatted Single Dimension Column Chart

Hi Community,

I was wondering if there is a way to take a single dimension in looker and conditionally format to a specific choice or selection in looker.

So if I have one dimension named “brand” and my measure is “recommend score” my data is set up like this:

BRAND Recommend Score
brand A 56%
brand B 66%
brand C 54%
brand D 57%
brand E 62%

where i want to make the chart highlight brand C in a different color automatically, and if I were to select another brand (i.e. Brand A, B, D, or E) it would highlight in a third color.

So eventually I may have a chart that looks like this:

image

If there is a way you think I would need to set this up in the SQL portion / just in the visualization itself that would be much appreciated!

Cheers

You can do this using parameters! It requires a few steps.

  1. Create a parameter/filter to select brand A, brand B, etc. Something like:
  parameter: brand_selector {
    allowed_value: {
      label: "Brand A"
      value: "Brand A"
    }
    allowed_value: {
      label: "Brand B"
      value: "Brand B"
    }
etc etc
  }
  1. Then, create a dimension that always returns that parameter’s input. Example:
  dimension: selected_brand {
    type: string
    sql: {% parameter brand_selector %} ;;
  }
  1. Build an explore where you select Brand, Selected Brand, and your Recommend Score.
    Here’s my example, using differently named fields. userid is Brand, Viewer ID is Selected Brand, and totaltopscore is Recommend Score:

  2. Add 2 table calculations, call them “Selected Score” and “Other Score”
    They’ll look like:

selected score

if(${brand}=${selected_brand},${recommend_score},null)

and
other score

if(${brand}=${selected_brand},null,${recommend_score})
  1. Hide Recommend Score from the visualization so you’re left with just the two table calculations. Color them differently, and you’re set! It will change dynamically based on what brand you select with the parameter.

Example with my different field names:

1 Like

If you’d prefer not to use table calcs- see my reply here. I discuss using measures instead. The benefit to using measures is that it will preserve drill functionality.

Cheers,
Adina

1 Like