expect_column_values_to_be_increasing
How it Works
The expect_column_values_to_be_increasing test from the dbt-expectations package validates that values in a column are monotonically non-decreasing (or strictly increasing, if configured). This is useful for validating sequential IDs, timestamps, or running totals that should always move forward.
The strictly argument (default false) controls whether equal consecutive values are acceptable.
Steps and Conditions
- Column Selection: Identify the column to validate.
- Optional Sort: Specify
sort_columnandsort_column_descto define ordering. - Strictness: Set
strictly: truefor strictly increasing,falsefor non-decreasing. - Execution: Each value is compared to the previous row's value.
- Outcome: Pass if the sequence is monotonically increasing; fail if any decrease is detected.
Example Usage: Sequence IDs
A data engineering team maintains an event_sequence column that must always increase with each new record inserted.
models:
- name: event_log
columns:
- name: event_sequence
tests:
- dbt_expectations.expect_column_values_to_be_increasing:
strictly: true
sort_column: inserted_atAny out-of-order or duplicate sequence values fail the test, alerting the team to event ordering issues.
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.