<@U088WCP3B4P> i am trying to use elementary artif...
# ask-elementary-ai
h
@kapa.ai i am trying to use elementary artifact metrics_anomaly_score, but looks like the avg , stdev and anomaly_score caluclations in the view are not aligned with the elementary dashboard. the avg and stdev are calculated for a metric for the whole table and not per slice. Is this a bug ?
k
Yes, this is a known bug in Elementary. The
metrics_anomaly_score
view computes
training_avg
,
training_stddev
, and consequently
anomaly_score
using a window function partitioned only by
metric_name
,
full_table_name
, and `column_name`:
Copy code
avg(metric_value) over (
  partition by metric_name, full_table_name, column_name
  order by bucket_start asc
  rows between unbounded preceding and current row
) as training_avg
This means the statistics are calculated across all dimension values combined, rather than per slice/dimension value. [Partition bug] The expected behavior (as described in the GitHub issue) is that the partition should also include
dimension
and `dimension_value`:
Copy code
avg(metric_value) over (
  partition by metric_name, full_table_name, column_name, dimension, dimension_value
  order by bucket_start asc
  rows between unbounded preceding and current row
) as training_avg
This discrepancy explains why the
metrics_anomaly_score
view shows different averages/stddevs than what the Elementary dashboard displays — the dashboard likely computes stats per dimension value correctly, while the view does not. [Partition bug] Current status: The GitHub issue was closed due to inactivity (marked stale), but based on the knowledge sources, the fix has not been confirmed as merged into a specific release. The SQL in version 0.21.0 still shows the problematic partitioning. [Partition bug] Workaround: You can locally override
metrics_anomaly_score.sql
in your own dbt project by copying the package SQL and adding
dimension, dimension_value
to the
partition by
clause in all window functions. To do this: 1. Disable the package model in `dbt_project.yml`models elementary: metrics_anomaly_score: +enabled: false 2. Create
models/elementary_overrides/metrics_anomaly_score.sql
with the corrected partition:avg(metric_value) over ( partition by metric_name, full_table_name, column_name, dimension, dimension_value order by bucket_start asc rows between unbounded preceding and current row ) as training_avg, {{ elementary.standard_deviation('metric_value') }} over ( partition by metric_name, full_table_name, column_name, dimension, dimension_value order by bucket_start asc rows between unbounded preceding and current row ) as training_stddev [local override] I'd recommend also checking the Elementary Slack or reopening the GitHub issue to confirm whether a fix has been released in a version newer than 0.21.0. 👍 0 button 👎 0 button â„šī¸ Tip: Mention @elementary.ai in the thread for follow-ups or DM the app for 1-to-1 help.