expect_column_values_to_be_between
How it Works
The expect_column_values_to_be_between test from the dbt-expectations package validates that every individual value in a column falls within a specified minimum and maximum range. This is a row-level range check, unlike expect_column_max_to_be_between or expect_column_min_to_be_between which check aggregate statistics.
An optional row_condition can scope the check, and strictly makes boundaries exclusive.
Steps and Conditions
- Column Selection: Identify the numeric column to validate.
- Define Range: Set
min_valueand/ormax_value. - Optional Config: Apply
row_conditionandstrictlyas needed. - Execution: Each row's value is individually checked against the range.
- Outcome: Pass if all values are within range; fail if any fall outside.
Example Usage: Temperature Monitoring
A cold chain logistics company monitors refrigerated storage temperatures. Every recorded temperature must stay between 2°C and 8°C to ensure compliance.
models:
- name: storage_temperature_log
columns:
- name: temperature_celsius
tests:
- dbt_expectations.expect_column_values_to_be_between:
min_value: 2
max_value: 8
row_condition: "storage_type = 'refrigerated'"Any temperature reading outside the compliance range immediately fails the test, triggering a regulatory alert.
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.