calogica / dbt-expectations

Port(ish) of Great Expectations to dbt test macros
https://calogica.github.io/dbt-expectations/
Apache License 2.0
989 stars 120 forks source link

[Feature Request] Test row-on-row percent change #281

Open dtger opened 10 months ago

dtger commented 10 months ago

Is your feature request related to a problem? Please describe. There exist tests to compare values within the column, and test if they are increasing or decreasing. However there is no solution to define acceptable rate of change.

Describe the solution you'd like I would like to have an ability to compare relative differences between ordered values within a column.

For example:

Ability to define acceptable percentage change in value from one row to the next is what I'm after. In the example above, we define threshold run test to compare whether than threshold has been met, ie:

select *
from table_name
where not(abs(test_column / nullif(previous_test_column_value, 0) - 1 < change_threshold))

where

Describe alternatives you've considered There are no alternatives I have found that solved this specific case

Additional context PR incoming, as I have the test running in my current project