Gustavo Santos
10/09/2025, 8:19 PMkapa.ai
10/09/2025, 8:19 PMkapa.ai
10/09/2025, 8:19 PMyaml models: - name: your_model columns: - name: your_metric_column tests: - elementary.column_anomalies: column_anomalies: - sum dimensions: - category_column - another_dimension The documentation specifies that the dimensions parameter can be a list of SQL expressions, so you can use SQL code (such as CASE statements or window functions) to define your grouping logic. Each unique combination of dimension values will be monitored separately for anomalies. This feature is available for column_anomalies, all_columns_anomalies, and dimension_anomalies tests. It is recommended to use low-cardinality fields for dimensions to avoid excessive segmentation and performance issues. For more details and examples, see the official documentation on dimensions and recent changelog updates introducing this feature [Dimensions configuration](https://docs.elementary-data.com/data-tests/anomaly-detection-configuration/dimensions), [Column anomalies by dimensions](https://docs.elementary-data.com/changelog#column-anomalies-by-dimensions). If you want to use more complex SQL logic, you can include SQL expressions in the dimensions list, such as: yaml dimensions: - CASE WHEN region = 'US' THEN 'North America' ELSE 'Other' END - product_category This will group your anomaly detection by the result of the SQL expression and the product_category column. In summary: Yes, you can use SQL code in the dimensions parameter of a column_anomalies test to group your metric for anomaly detection.Gustavo Santos
10/09/2025, 8:21 PMcolumn_name: affiliate_commissions
config:
group_by_columns: [site, utm_source] # was shop_name, affiliate_session_traffic_channel
time_bucket: { period: day, count: 1 }
training_period: 28
detection_period: 3
anomaly_sensitivity: 3.2
where_expression: "event_date >= DATE_SUB(CURRENT_DATE(), INTERVAL 35 DAY)"
severity: warn
column_anomalies: [sum]
min_training_set_size: 21
anomaly_direction: "drop"
seasonality: "day_of_week"kapa.ai
10/09/2025, 8:21 PMkapa.ai
10/09/2025, 8:21 PMyaml column_name: affiliate_commissions config: dimensions: - site - utm_source time_bucket: period: day count: 1 training_period: 28 detection_period: 3 anomaly_sensitivity: 3.2 where_expression: "event_date >= DATE_SUB(CURRENT_DATE(), INTERVAL 35 DAY)" severity: warn column_anomalies: - sum min_training_set_size: 21 anomaly_direction: "drop" seasonality: "day_of_week" - Replace group_by_columns with dimensions. - The dimensions parameter accepts a list of columns or SQL expressions to group by. - This will monitor the sum of affiliate_commissions for each (site, utm_source) combination separately for anomalies. For more details, see the official documentation on [dimensions configuration](https://docs.elementary-data.com/data-tests/anomaly-detection-configuration/dimensions) and [column_anomalies test configuration](https://docs.elementary-data.com/data-tests/anomaly-detection-tests/column-anomalies#test-configuration).Gustavo Santos
10/09/2025, 8:25 PMkapa.ai
10/09/2025, 8:25 PMkapa.ai
10/09/2025, 8:25 PMyaml column_name: affiliate_commissions config: dimensions: - UPPER(utm_source) - CASE WHEN site = 'main' THEN 'primary' ELSE 'secondary' END time_bucket: period: day count: 1 training_period: 28 detection_period: 3 anomaly_sensitivity: 3.2 where_expression: "event_date >= DATE_SUB(CURRENT_DATE(), INTERVAL 35 DAY)" severity: warn column_anomalies: - sum min_training_set_size: 21 anomaly_direction: "drop" seasonality: "day_of_week" This will group the anomaly detection by the uppercased utm_source and by whether site is 'main' or not. The documentation confirms that dimensions can be a list of SQL expressions, not just column names. Each unique combination of these expressions will be monitored separately for anomalies [dimensions configuration](https://docs.elementary-data.com/data-tests/anomaly-detection-configuration/dimensions). If you need more complex logic, you can use any valid SQL expression as an entry in the dimensions list.