Skip to main content
Using comparison
{% comparison_selector
    id="comp"
    default_value="prior year"
/%}

{% bar_chart
    data="demo_daily_orders"
    x="date"
    y="sum(total_sales)"
    date_grain="month"
    comparison={
        compare_vs={{comp}}
    }
/%}

Examples

Using comparison

Using comparison
{% comparison_selector
    id="comp"
    default_value="prior year"
/%}

{% bar_chart
    data="demo_daily_orders"
    x="date"
    y="sum(total_sales)"
    date_grain="month"
    comparison={
        compare_vs={{comp}}
    }
/%}

Attributes

id
string
required
The id of the comparison selector to be used in SQL query templates
preset_values
array
Optional array of preset comparison values to show. If not provided, all comparison options will be available.
default_value
string
Default comparison to select on loadAllowed values:
  • prior year
  • prior period
  • target
  • benchmark
title
string
default:"Comparison"
Text displayed above the selector
info
string
Information tooltip text
URL to link the info text to (can only be used with info)
Create a custom link title for the info link, placed after the info text (can only be used with info_link)
placeholder
string
Placeholder text displayed when no value is selected
icon
string
default:"triangle"
Icon to display
width
number
Set the width of this component (in percent) relative to the page width

Using the Filter Variable

Reference this filter using {{filter_id}}. The value returned depends on where you use it.
ContextDefault PropertyNo SelectionResult
Inline SQL query.comparison{"compare_vs": "prior year"}
where attribute.comparison{"compare_vs": "prior year"}
Text / Markdown.comparison{"compare_vs": "prior year"}

Available Properties

You can also access specific properties using {{filter_id.property}}:

.selected

Returns the selected comparison value with quotes. Returns an empty string when no value is selected.
{% comparison_selector id="comparison" preset_values=["prior year", "prior period"] /%}

```sql sales_comparison
select 
  date,
  sum(sales) as total_sales,
  '{{comparison.selected}}' as comparison_type
from orders
group by date
```
Example value: 'prior year'

.literal

Returns the raw unescaped selected value.
{% comparison_selector id="comparison" preset_values=["prior year", "prior period"] /%}

```sql sales_comparison
select 
  date,
  sum(sales) as total_sales,
  {{comparison.literal}} as comparison_type
from orders
group by date
```
Example value: prior year

.compare_vs

Returns the comparison type. Example value: prior year

.comparison

Returns the full comparison configuration as JSON. Use {{comp}} directly with compare_vs to dynamically configure comparisons.
{% comparison_selector id="comp" /%}

{% big_value 
    data="demo_daily_orders"
    value="sum(total_sales)"
    comparison={ compare_vs={{comp}} }
/%}
Example value: {"compare_vs": "prior year"}

.agg

For benchmark comparisons: returns the aggregation function. Example value: avg

.subject

For benchmark comparisons: returns the subject column that defines entities. Example value: region

.target

For target comparisons: returns the target value or expression. Example value: 100000

Allowed Children