<@U088WCP3B4P> is elementary support anomaly base ...
# ask-elementary-ai
a
@kapa.ai is elementary support anomaly base on sql expression (not just simple column)
k
A message from kapa.ai
Elementary does support some anomaly detection based on SQL expressions, but with important limitations depending on the test type: - For grouping or filtering data, you can use SQL expressions in the
dimensions
and
where_expression
parameters. For example, you can group anomaly detection by a SQL expression (not just a simple column) using the
dimensions
parameter in tests like
all_columns_anomalies
,
column_anomalies
, and
dimension_anomalies
. This allows you to segment your monitoring by any valid SQL expression, not just a single column name. For filtering,
where_expression
accepts any valid SQL expression to filter the data being tested [dimensions documentation](https://docs.elementary-data.com/data-tests/anomaly-detection-configuration/dimensions), [where_expression documentation](https://docs.elementary-data.com/data-tests/anomaly-detection-configuration/where-expression). - However, for monitoring a metric or anomaly directly on a SQL expression (e.g., the difference between two columns, or a calculated field that does not exist as a physical column), Elementary generally requires that the expression be materialized as a column in a model or view. You cannot directly specify an arbitrary SQL expression as the target column for anomaly detection in
column_anomalies
or similar tests. This is confirmed in community discussions, where users are advised to create a temporary model or view for such cases [Slack discussion](https://slack.com/archives/C02CTC89LAX/p1736408683199129). - There is an open feature request to allow setting an SQL expression as a timestamp column, but as of now, this is not natively supported [GitHub issue](https://github.com/elementary-data/elementary/issues/897). Summary: You can use SQL expressions for grouping (
dimensions
) and filtering (
where_expression
), but not as the direct subject of anomaly detection (i.e., you cannot monitor an arbitrary SQL expression as if it were a column, unless you materialize it first). If you need to monitor a calculated value, you should create a model or view with that calculation as a column, and then apply Elementary tests to it.