<@U088WCP3B4P> I want to add several distribution ...
# ask-elementary-ai
n
@kapa.ai I want to add several distribution tests to check the value frequencie of a column. I have the following: - elementary.anomaly_detection: metric: column_value_frequencies config: column_name: gender alias: gender_distribution description: Detects sudden anomalies in the distribution for gender meta: owner: loyalty However if i add multiple tests in one table like this then dbt throws an error that tests cant have the same name. My question: Is this the right way to go to check frequencies in values or is there a better option and second question is how I add multiple tests like this in 1 table?
k
A message from kapa.ai
To check the value frequencies (distribution) of a column in Elementary, the recommended approach is to use the
elementary.dimension_anomalies
test. This test is specifically designed to monitor the frequency of values in a configured dimension (column) over time and alert on unexpected changes in the distribution. It is best used on low-cardinality fields like
gender
 [Add anomaly detection tests](https://docs.elementary-data.com/data-tests/add-elementary-tests). Example configuration:
Copy code
yaml models:   - name: your_model     tests:       - elementary.dimension_anomalies:           dimensions:             - gender           meta:             owner: loyalty           description: Detects sudden anomalies in the distribution for gender
### Adding Multiple Distribution Tests on One Table If you want to check the distribution for multiple columns (e.g.,
gender
,
country
), you should define a separate
elementary.dimension_anomalies
test for each column. Do not list multiple dimensions in a single test if you want to monitor them independently, as this will combine the dimensions and check the joint distribution (e.g.,
gender
+
country
), not each separately. Here’s how to do it:
Copy code
yaml models:   - name: your_model     tests:       - elementary.dimension_anomalies:           dimensions:             - gender           meta:             owner: loyalty           description: Detects sudden anomalies in the distribution for gender       - elementary.dimension_anomalies:           dimensions:             - country           meta:             owner: loyalty           description: Detects sudden anomalies in the distribution for country
This way, each test is uniquely defined and dbt will not throw an error about duplicate test names. If you want to further distinguish tests (e.g., for different configurations on the same column), you can use the
alias
or
name
parameter to give each test a unique identifier. ### Summary - Use
elementary.dimension_anomalies
for value frequency/distribution checks. - Define a separate test for each column you want to monitor. - Use
alias
or
name
if you need multiple tests on the same column with different configs. - Do not list multiple dimensions in one test unless you want to check the joint distribution. For more details, see the official documentation and community guidance [here](https://docs.elementary-data.com/data-tests/add-elementary-tests) and [here](https://slack.com/archives/C02CTC89LAX/p1668437656150669).