Almost every dashboard eventually needs buckets: order sizes, customer age bands, days-to-ship ranges, or named segments such as "Enterprise" and "SMB". LookML offers three native ways to do this. Each has different trade-offs for sort order, filtering, and maintainability.
Option 1: type: tier
Use tier when you want numeric ranges with evenly defined edges.
dimension: order_amount_tier {
type: tier
tiers: [0, 25, 50, 100, 250]
style: integer
sql: ${order_amount} ;;
}
This produces labels such as 0 to 24, 25 to 49, and 250 or Above. The style parameter controls label format:
classic(default):T00 (0.0,25.0)style labelsinterval:0.0 to 25.0integer:0 to 24, best for whole numbersrelational:< 25,>= 25 and < 50
Tiers sort numerically by default, which is the main reason to prefer them over hand-written CASE statements for ranges. Note that values below the first tier edge land in a Below 0 bucket, so choose your first edge deliberately.
Option 2: Equal-width bins in SQL
Looker's Explore UI can create custom bins in the field picker, but those are per-user and not versioned. When you need fixed, shared buckets, define them in LookML. For equal-width buckets, compute the bucket in SQL:
dimension: days_to_ship_bucket {
type: number
sql: FLOOR(${days_to_ship} / 5) * 5 ;;
value_format: "0"
}
This gives numeric output (0, 5, 10, ...), which sorts correctly and can be used in charts as an axis. Add a label dimension later if you want friendlier text.
Option 3: case for named segments
When buckets have business names or depend on several columns, use case.
dimension: customer_segment {
case: {
when: {
sql: ${lifetime_value} >= 10000 ;;
label: "Enterprise"
}
when: {
sql: ${lifetime_value} >= 1000 ;;
label: "Mid-Market"
}
else: "SMB"
}
}
Conditions are evaluated top to bottom, so order from most to least restrictive. By default, case results sort in the order you declared them, which is usually what you want for segments. If you would rather sort alphabetically, add alpha_sort: yes.
Choosing between them
| Need | Use |
|---|---|
| Numeric ranges, numeric sort | tier |
| Equal-width buckets for charts | SQL FLOOR bucket |
| Named segments or multi-column logic | case |
Pitfalls
- Filtering on a tier: filtering by a
tierdimension is applied as aCASEexpression in SQL, which can prevent partition pruning in your warehouse. If the underlying number is available, filter on that field instead and expose the tier only for grouping. - Measures inside buckets: tiering a measure does not work directly. Wrap the aggregation in a derived table or use a
type: numberdimension on a per-row value, then aggregate it. - Null values:
tierplaces nulls in a separate null bucket;casesends them toelse. Handle them explicitly if reports should show an "Unknown" label. - Duplicated logic: define segments once in a shared view and
extendsorrefinementthem, rather than copyingcaseblocks across models. - Changing edges: re-bucketing changes historical numbers. Document changes in the field
descriptionso analysts know the definition.
Make buckets self-explanatory
Add description and group_label so users understand the logic:
dimension: customer_segment {
description: "Based on lifetime value: Enterprise >= 10k, Mid-Market >= 1k, otherwise SMB."
group_label: "Customer"
...
}
Clear descriptions also help AI-assisted features in Looker interpret your model correctly.
Summary
Use tier for numeric ranges, a SQL expression for equal-width buckets, and case for named business segments. Keep definitions in LookML, not in per-user Explore bins, so every dashboard agrees. If your model has accumulated inconsistent segment logic, the Vistelio team can help review and consolidate it.