Announcements
This site is in read only until July 22 as we migrate to a new platform; refer to this community post for more details.

Parameter to display round number or decimal

Hello,

I'd like to add a filter/parameter in a dashboard that controls whether the displayed dashboard numbers are rounded or are decimal. 

I've tested some solutions but unfortunately there are some compatibility issues with scatterplot and line charts and also I'm wondering of the appropriate to accommodate the html formatting also in drilldowns

1 1 141
1 REPLY 1

The only way I can think to do this involves creating measures that each have two different definitions in the SQL parameter, one for rounding and one for decimals. The parameter would be used together with Liquid to choose which definition to use. I got Gemini to generate the sample code below, hopefully it will convey the idea.

view: sales {
  sql_table_name: your_sales_table ;;

  dimension: sales_value {
    type: number
    sql: ${TABLE}.sales_value ;;
  }

  dimension: date {
    type: date
    sql: ${TABLE}.date ;;
  }

  parameter: rounding {
    type: unquoted
    allowed_value: {
      label: "Rounded"
      value: "rounded"
    }
    allowed_value: {
      label: "Two Decimal Places"
      value: "decimal"
    }
    default_value: "rounded"
  }

  measure: total_sales_value {
    type: number
    sql:
      {% if rounding._parameter_value == 'rounded' %}
        ROUND(${sales_value})
      {% elsif rounding._parameter_value == 'decimal' %}
        ROUND(${sales_value}, 2)
      {% endif %}
     ;;
  }
}

 

Top Labels in this Space