Filters
When creating features on an entity, it is possible to filter the entities and data assets we create feature from using the filters property.
See the following example:
# customer.yml
features: 
- type: metric
  name: orders_count_2025
  asset: db_prod.core.orders
  measures: count_orders
  filters:
  - type: sql
    sql: "{asset}.{order_date} >= '2025-01-01' and {asset}.{order_date} <= '2025-12-31'"
- type: metric
  name: successful_orders_count
  asset: db_prod.core.orders
  measures: count_orders
  filters:
  - type: fields
    field: order_status
    operator: is
    values:
    - successfilters
filtersFilters are defined in the filters property. This is an array that can get as many filter inputs as needed, where each input can be defined as a SQL statement or a YAML statement (type : sql / field).
type
typeUse the filters type property to determine which method to use for the filter.
The options for type are:
- sql
- field
sql (type)
sql (type)Use sql code to define how a data asset should be filtered.
When setting type: sql, you will need to add the sql property with the SQL definition of the relation.
In this example, we use SQL to filter the orders data asset to retrieve only records where the order_date field is in 2025 for the feature orders_count_2025.
# customer.yml
features: 
- type: metric
  name: orders_count_2025
  asset: db_prod.core.orders
  measures: count_orders
  filters:
  - type: sql
    sql: "{asset}.{order_date} >= '2025-01-01' and {asset}.{order_date} <= '2025-12-31'"fields (type)
fields (type)Use simple YAML-style to define how a data asset should be filtered.
When setting type: fields, you will need to add the fields property with the fields and the operator that define the relation.
Example (fields):
fields):# customer.yml
features: 
- type: metric
  name: successful_orders_count
  asset: db_prod.core.orders
  measures: count_orders
  filters:
  - type: fields
    field: order_status
    operator: is
    values:
    - successIn the above example we filter the data asset db_prod.core.orders to retrieve only records where the value of the field order_status is 'success'.
Using the filters type fields, the following properties should be specified:
field
fieldThe field name in the data asset, which we would like to apply a filtering logic on.
Operator
OperatorThe operator to be applied on the field , that defines the logic of which values we would like to filter in the results. The options for the operator property are:
is
isEquals to.
"A equals B" translates to "A = B".
Usage example (is operator):
...
  filters:
  - type: fields
    field: order_status
    operator: is
    values:
    - successRetrieves only records where the value of the field order_status is 'success'.
is_not
is_notDoes not equal to.
"A is_not B" translates to "A != B" (or "A <> B").
Usage example (is_not operator):
...
  filters:
  - type: fields
    field: order_status
    operator: is_not
    values:
    - successRetrieves only records where the value of the field order_status is not 'success'.
between
betweenBetween two values
"A between B and C" translates to "A >= B and A <= C
Usage example (between operator):
...
  filters:
  - type: fields
    field: order_date
    operator: between
    values:
    - 2024-01-01
    - 2025-01-01Retrieves only records where the values of the field order_date are between '2024-01-01' and '2025-01-01'.
Note that the order matters - the first value is the lower bound and the second value is the upper bound of the between operator.
gt
gtGreater than.
"A gt B" translates to "A > B".
Usage example (gt operator):
...
  filters:
  - type: fields
    field: order_amount
    operator: gt
    values:
    - 100Retrieves only records where the value of the field order_amount is greater than 100.
gte
gteGreater than or equals to.
"A gte B" translates "to a >= b".
Usage example (gte operator):
...
  filters:
  - type: fields
    field: order_amount
    operator: gte
    values:
    - 100Retrieves only records where the value of the field order_amount is greater than or equals 100.
lt
ltLower than.
"A lt B" translates "to a < b".
Usage example (lt operator):
...
  filters:
  - type: fields
    field: order_amount
    operator: lt
    values:
    - 100Retrieves only records where the value of the field order_amount is lower than 100.
lte
lteLower than or equals to.
"A lte B" translates "to a <= b".
Usage example (lte operator):
...
  filters:
  - type: fields
    field: order_amount
    operator: lte
    values:
    - 100Retrieves only records where the value of the field order_amount is lower than or equals 100.
is_set
is_setThe value is not NULL.
"A is_set" translates to "A is not null".
Usage example (is_set operator):
...
  filters:
  - type: fields
    field: order_amount
    operator: is_setRetrieves only records where the value of the field order_amount is set. Meaning, order_amount is not Null.
Note that in the case of the operator is_set there is no need to add the values property.
is_not_set
is_not_setThe value is NULL.
"A is_not_set" translates to "A is null".
Usage example (is_not_set operator):
...
  filters:
  - type: fields
    field: order_amount
    operator: is_not_setRetrieves only records where the value of the field order_amount is not set. Meaning, order_amount is Null.
Note that in the case of the operator is_not_set there is no need to add the values property.
Values
ValuesThe values to accept.
Lynk will apply the operator logic to the field and the given values. The records that will return are the records where that filtering logic returns "true" (see this example)\
Last updated
