[Feature Request] Test row-on-row percent change
dtger opened this issue · comments
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:
- order column could be date, and
- values could be sales volume (£)
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
test_column
is the column we're testing for changes inprevious_test_column_value
=lag(test_column)
change_threshold
is ratio of change we find acceptable, expressed as fractional percent (10% = 0.1)
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