Have you ever drilled into a measure and found more rows than the number you clicked? This usually happens when the measure’s conditions are written inside its SQL. Drill-down doesn’t carry those conditions over, so it returns every underlying row. This community post from Conner explains why in more detail and how to use filters parameter to apply conditions on a measure.
This post picks up from there: what to do when your measure has several conditions, and how to apply them all with a single filter using a helper dimension**.**
The scenario
Say you have a Completed Domestic Orders measure on an orders view. The number is only supposed to count orders that meet all of these conditions:
order_statusisDeliveredis_internationalisfalseorder_dateis in the current quarterpayment_statusisPaid
In the IDE, your measure would be defined in SQL that looks like this:
measures:
completed_domestic_orders:
sql: |
SUM(
CASE
WHEN ${order_status} = 'Delivered'
AND ${is_international} = false
AND ${order_date} >= DATE_TRUNC('quarter', CURRENT_DATE)
AND ${payment_status} = 'Paid'
THEN 1 ELSE 0
END
)
Option 1: One filter per condition
Move each condition into the measure’s filters parameter. Filters remove rows before aggregation, and when you drill, Omni applies them to the detail rows too:
measures:
completed_domestic_orders:
aggregate_type: count
filters:
order_status:
is: Delivered
is_international:
is: false
payment_status:
is: Paid
order_date:
is: this quarter
The number and the drill now match. This works well for two or three conditions.
Option 2: Combine the conditions into a helper dimension
With many conditions, or when several measures share the same logic, the filters block gets long and the definitions can drift apart. Instead, put the whole rule in one boolean dimension:
dimensions:
is_completed_domestic_order:
sql: |
CASE
WHEN ${order_status} = 'Delivered'
AND ${is_international} = false
AND ${order_date} >= DATE_TRUNC('quarter', CURRENT_DATE)
AND ${payment_status} = 'Paid'
THEN true
ELSE false
END
Then filter the measure on that single dimension:
measures:
completed_domestic_orders:
aggregate_type: count
filters:
is_completed_domestic_order:
is: true
Drilling into the measure now returns exact number of rows that make up the number, with one filter instead of four.
So why use a helper dimension?
- One place to edit. Change the rule once and every measure that uses it updates.
- Easy to reuse. Add it to other measures (for example, a revenue measure with the same conditions) or use it as a dashboard filter.
- Easy to audit. Add the dimension to a table to see which rows are true or false, which is a quick way to check the logic.
Happy Modeling!