expect_column_sum_to_be_between
dbt-expectations
·
Column
·
Aggregation, Values range
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.
If total payroll spikes or drops outside the expected band, the test fails and prompts a review.

