expect_column_values_to_be_decreasing
How it Works
The expect_column_values_to_be_decreasing test from the dbt-expectations package validates that values in a column are monotonically non-increasing (or strictly decreasing if configured). This is the counterpart to expect_column_values_to_be_increasing and is useful for validating descending rankings, countdown sequences, or metrics that should always decrease over time within a given partition.
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 decreasing,falsefor non-increasing. - Execution: Each value is compared to the previous row's value.
- Outcome: Pass if the sequence is monotonically decreasing; fail if any increase is detected.
Example Usage: Rank Tables
A competitive gaming platform generates weekly player rankings ordered from highest to lowest score. The rank column should always decrease (i.e., go from 1 toward the bottom).
models:
- name: weekly_player_rankings
columns:
- name: score
tests:
- dbt_expectations.expect_column_values_to_be_decreasing:
strictly: false
sort_column: rankAny increase in score down the ranked list would indicate a data ordering error in the ranking model.
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.