Goal
Conditional Filtering lets the semantic layer detect and respond to filters coming from a BI tool or an AI agent, so that metric logic can adapt dynamically to the user’s query context. So, instead of blindly applying the same transformation or metric calculation every time, the semantic logic can take into consideration the filters the user provided (likeregion = Europe
, or date >= 2024-01-01
).
That allows to create default data filtering, and to adjust business logic based on user intent.
Syntax
- Single field (
entity.field
) to detect user filters on - Default value expression in case no user filters on
entity.field
were provided. If not set, the default value isNULL
.
- The filter value if the BI or AI query filtered
entity.filter
to a single value, i.e. For the user filterentity.field = 'value'
, then would returnvalue
- The default value if there was no equality filter.
Honeydew uses Conjunctive Normal Form (CNF) decomposition to detect equality filters even when they’re embedded in complex expressions.
GET_FIELD_SELECTION(entity.field)
and a user filter -
The following examples would all return value
given the filter for it:
entity.field = 'value'
entity.field IN ('value')
entity.field = 'value' AND entity.other_field = 'other_value'
NULL
(or the default value if set):
entity.field || '' = 'value'
entity.field IN ('value', 'other')
entity.field = 'value' OR entity.other_field = 'value'
entity.field >= 'a'
Using GET_FIELD_SELECTION with Power BIPower BI filtering is case insensitive. To support Power BI, always use same (lower or upper) case values.
Use Cases
Change Calculation Based on User Intent
Use the filter a user has supplied to change how a metric is calculated. This is most commonly used to create different metric is calculations at different grains, over the same data. Examples: Dynamic cohorts Given adim_cohort
defining user cohorts, simulate based on cohort choice
dim_grain
selector entity, choose how a metric is calculated at each grain
(See Metrics with different grains).
Most business logic does not care about user filters, and is only based on the data.For example when want to calculate differently for 2023 and 2024, then whether the user chose 2023 or 2024
does not matter. How to calculate is a property of the data, not what the user wanted:However, when exactly the same data is differently processed based on user intent then must look at user filters,
as in the
total_sales_simulated_tax
example above.Default Filtering
Apply a filter on the data by default, unless a user has instructed otherwise. This is used for:- Reduce Cost & Improve Performance with BI: when users build new BI reports, they would typically send unfiltered queries looking at all the data. They usually don’t want to aggregate all the data, but they may have dragged a metric on a dashboard first and a date filter only after. Default filtering enables to apply a filter on the data until the user decided to change it. For example, force a “last 2 weeks” filter on the big fact tables up until the user explicitly asked for more.
- Ensure Correctness By Removing Duplicated Data: in some data modeling scenarios, data may have multiple versions recorded. Aggregating on the data would result in double counting and a wrong result. Default filtering enables to enforce choosing a specific version of the data, always ensuring there is no double counting.
GET_FIELD_SELECTION
with Domain Source Filters.
For example, add a source filter such as
- Default filter for performance filtering
- Default filter for multi-grain data.
- Default filter for slowly changing dimensions