Displaying values from other fields in the tooltip

(Zachary Michel) #1

Disclaimer: This solution utilizes liquid to display values from another field. It may not be the best solution, but I thought it would be fun to share. It could be considered hacky by some.

Pre-requisite materials

Teaser

How it’s done
This pattern may be used to display any combination of values on a visualization, however there are a few important points to make sure of.

  • Make sure that the html: goes into the measure that is going to be used as the y-axis.
  • The value which you would like to display on the y-axis should be the value in the sql: statement.
  • When using any measure that is formatted, i.e. percent_of_total or a measure with value_format, make sure to use {{ field_name._rendered_value }} where field_name is the actual name of the measure/dimension.

I utilized liquid _rendered_value to display the formatted values for both the Total Gross Margin, which is formatted to 2 decimals, and the Percent of Total GM measures in one html tag.

In my particular example, I created a gross_margin_tier dimension to group my data set by, and a total_gross_margin type: sum measure as my computation.

My goal was to display the percent_of_total_gm for each tier’s total_gross_margin within the hover over, while keeping the y-axis distinct to the total_gross_margin. Here is how I created the viz/table above:

  - dimension: gross_margin_tier
    type: tier
    sql: ${gross_margin}
    tiers: [0, 50, 100, 200, 400]

  - measure: percent_total_gm
    type: percent_of_total
    sql: ${total_gross_margin}

  - measure: total_gross_margin
    type: sum
    decimals: 2
    sql: ${gross_margin}
    html: |
      {{ rendered_value }} || {{ percent_total_gm._rendered_value }} of total
2 Likes

Chart tooltip annotations
How to enable tooltip for dimension/measure so description will display to the user when they mouse over object name in look (Table)
Show percent_of_total and count in the same chart bar
Hover to show additional data hidden from visualization
Measure vs. Measure Scatterplots (3.28+)
Display % of totals on a stacked bar graph
Tooltip from hidden field in Visualizations
Can a user annotate the given chart in looker?
Show last (current) value of a trend line
(Morgan Imel) #2

It’s worth noting that if you reference a dimension using liquid, that dimension will be added to the underlying query and will be grouped by.

0 Likes

(Lukasz) #3

I tried to apply this trick to Timeline viz, to annotate details. It seems however that the timeline object does not support tooltips. Is that correct?

0 Likes

(allegra) #4

Hi there @Lukasz_Korbolewski! Tooltip is not currently supported in timeline visualizations! But I am happy to mention this to our product team :slight_smile:

1 Like

(Lukasz) #5

Thanks, it would be really nice to have.

0 Likes

(Vishal Parikh) #6

Note the above will break the ability to click and drill down. If you want to preserve that ability, you should do

<a href="#drillmenu" target="_self">{{rendered_value}} ({{count._rendered_value}})</a>
0 Likes

(Sean Higgins) #7

Slightly related, you can add a basic hover tooltip to Single Value, Single Record and Table visualisations with this:

 measure: user_reactivation_rate {
  type:sum 
  value_format_name:percent_1
  drill_fields: [detail*]
  sql: ${TABLE}.user_reactivation_rate ;;
  description: "User Reactivation Rate"
  html: <span title="Reactivation Definition: 
  The rate at which a user re-engages with our platform">{{linked_value}}</span>;;
  }

This doesn’t translate over to other chart types like bar/column as you don’t hover over the rendered value.

2 Likes

(Jonathan Tao) #8

To add to Sean’s post, the cell tooltip can also reference other fields as long as you put the correct liquid into the html title tag. This can get around the issue where the table viz inherently doesn’t have the Looker tooltip featured in the other viz types, but can leverage a HTML title tag tooltip.

  measure: count_unique_customers {
    type: count_distinct
    sql: ${customer_id} ;;
    html:
    <span title="Avg session time: {{view_name.average_session_time_minutes._rendered_value}}">{{value}}</span>
    ;;
  }

58%20PM

0 Likes