expect_column_max_to_be_between
dbt-expectations
·
Column
·
Values distribution, Values range
How it Works
The expect_column_max_to_be_between test from the dbt-expectations package validates that the maximum value found in a given column falls within a specified range. This is especially useful for catching outliers or erroneous spikes that could signal upstream data issues.
The test computes the column's maximum value and then verifies it sits between an optional min_value and max_value. You can also configure group-by columns to assess subsets of the data independently, use a row_condition to filter rows before evaluation, and set strictly: true to make the comparison exclusive of boundary values.
Steps and Conditions
Column Selection: Identify the column whose maximum value you want to validate.
Define Range: Set
min_valueand/ormax_valueto establish acceptable boundaries.Optional Config: Apply
group_by,row_condition, andstrictlyflags as needed.Execution: The test computes the max and checks if it falls within range.
Outcome: Pass if the max is within bounds; fail if it falls outside.
Example Usage: SaaS Billing
A SaaS company wants to ensure that monthly invoice amounts never exceed their highest pricing tier and are always at least $1.
This ensures that no paid invoice unexpectedly exceeds $50,000, which could indicate a billing error, and that the maximum paid invoice is at least $1, ruling out zero-value anomalies.

