expect_column_mean_to_be_between
How it Works
The expect_column_mean_to_be_between test from the dbt-expectations package validates that the arithmetic mean of a numeric column's values falls within a defined range. This guards against data issues that shift the average — such as erroneous zero values inflating or deflating the mean, or data truncation removing high-value records.
Supports group_by, row_condition, and strictly for exclusive comparisons.
Steps and Conditions
- Column Selection: Choose the numeric column to evaluate.
- Define Range: Set
min_valueand/ormax_valuefor the acceptable mean. - Optional Config: Apply
group_by,row_condition, andstrictlyas needed. - Execution: The mean is computed and compared to the range.
- Outcome: Pass if within range; fail otherwise.
Example Usage: Customer Success
A customer success team tracks average NPS scores per quarter. The mean score should remain between 20 and 80 — extreme deviations likely indicate data collection errors.
models:
- name: quarterly_nps
columns:
- name: nps_score
tests:
- dbt_expectations.expect_column_mean_to_be_between:
min_value: 20
max_value: 80A mean outside this range prompts a review of the NPS data collection pipeline.
Interested to Learn More? Try Out the Free 14-Days Trial
One AI-native workspace to build, ship, and monitor dbt™ — without the tool sprawl.
Join industry leaders winning with DinoAI agents
Data engineers and analysts at the most AI-native startups and enterprises use Paradime's DinoAI agents everyday to become market leaders.