Please check out the original documentation for most up-to-date information.
type: number is used with numbers or integers. A measure of type: number does not perform any aggregation, and is meant to perform simple transformations on other measures. If you are defining a measure based on another measure, the new measure must be of type: number to avoid nested-aggregation errors.
The sql parameter for type: number measures can take any valid SQL expression that results in a number or an integer.
type: number fields can be formatted by using the value_format or value_format_name parameters.
For example, the following LookML creates a measure called total_gross_margin_percentage based on the total_sale_price and total_gross_margin aggregate measures, then displays it in a percentage format with two decimals (12.34%):
measure: total_sale_price {
type: sum
value_format_name: usd
sql: ${sale_price} ;;
}
measure: total_gross_margin {
type: sum
value_format_name: usd
sql: ${gross_margin} ;;
}
measure: total_gross_margin_percentage {
type: number
value_format_name: percent_2
sql: ${total_gross_margin}/ NULLIF(${total_sale_price},0) ;;
}
The example above also uses the NULLIF() SQL function to remove the possibility of division-by-zero errors.
Things to consider for type: number
There are several important things to keep in mind when using type: number measures:
- A measure of type: number can perform arithmetic only on other measures, not on other dimensions.
- Looker’s symmetric aggregates will not protect aggregate functions in the SQL of a measure type: number when computed across a join.
- The filters parameter cannot be used with type: number measures, but the filters documentation explains a workaround.
- type: number measures will not provide suggestions to users.
The Measure Types documentation page details more information about all current supported measure types:
- Measure type categories
- List of type definitions
- average
- average_distinct
- count
- count_distinct
- date
- list
- max
- median
- median_distinct
- min
- number
- percent_of_previous
- percent_of_total
- percentile
- percentile_distinct
- running_total
- string
- sum
- sum_distinct
- yesno