Dynamically display an image in a Dashboard, based on a filter

Knowledge Drop

Last tested: Oct 30, 2019
 

There's a few components to this, but it's easier than you might think! At a high level we will be using Liquid and a bit of front end wizardry.

1 - LookML

 

### we're starting with this field, which references a database column with customers

dimension: customer {

type: string

sql: ${TABLE}.customer ;;

}

dimension: customer_img {

type: string

sql: ${TABLE}.customer ;;

### each if statement should be evaluating the field, then spitting out an image

### replace customer here with the name of your field

### replace the values with the values from the database column

### insert elsif statements for more images

html:

{% if customer._value == "customer1" %}

<img src="https://www.mydomain.com/images/myimage1" />

{% elsif customer._value == "customer2" %}

<img src="https://www.mydomain.com/images/myimage2" />

{% else %}

<img src="https://www.mydomain.com/images/myimage1" />

{% endif %} ;;

}

2 - In your Explore

Navigate to your explore and do the following:

  • Filter on customer (any value)
  • Limit the table to 1 row
  • Change visualization type to single value viz type, and hide all columns except for your customer_img field

Your Explore should look something like this:

image.png

Add that to a dashboard and we're on to step 3!

3 - Your Dashboard

With the explore from step 2 on your dashboard as a tile, do the following:

  • Create a filter on the dashboard. The filter should be a field filter on the the column that holds all your customer/brand names.
  • In Tiles to Update add the image tile and select the customer/brand name field
  • Optionally, require a filter to run the dash and toggle off allow multiple filter values

Your filters will look something like this:

image.png

Voila!

image.png

This content is subject to limited support.                

Version history
Last update:
‎07-07-2021 01:15 PM
Updated by: