expect_column_sum_to_be_between
How it Works
The expect_column_sum_to_be_between test from the dbt-expectations package validates that the total sum of all values in a numeric column falls within a specified range. This is useful for validating financial totals, volume metrics, or any aggregate that should remain within predictable bounds across a data refresh.
Options include group_by, row_condition, and strictly for exclusive boundary comparisons.
Steps and Conditions
- Column Selection: Choose the numeric column to sum.
- Define Range: Set
min_valueand/ormax_value. - Optional Config: Apply
group_byandrow_conditionto refine scope. - Execution: The sum is computed and compared to the range.
- Outcome: Pass if the sum is within range; fail otherwise.
Example Usage: Payroll
A payroll system wants to ensure that the total gross salary disbursed each month stays within an expected range, guarding against erroneous mass payroll entries.
models:
- name: monthly_payroll
columns:
- name: gross_salary
tests:
- dbt_expectations.expect_column_sum_to_be_between:
min_value: 500000
max_value: 2000000
row_condition: "pay_period = current_pay_period"If total payroll spikes or drops outside the expected band, the test fails and prompts a review.
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.