Trying to get a rolling count that resets when 0 is hit.
Only need a few fields.
- Ordered by the date field and then ref field
- when value goes 0 to >0 count begins at 1
- If value remains same or increases count goes to 2 and beyond
- if value goes to 0 count goes back to 0
- repeats if value changes to >0 again at 1
Date:
Date Ref Value Count
202201 170532 £300.21 1
202202 170532 £600.42 2
202203 170532 £0.00 0
202204 170532 £300.21 1
202205 170532 £600.42 2
202206 170532 £900.63 3
.. ..
Tried a few things i've read on here but not having much joy.
Thanks for any help or direction provided!
1条答案
按热度按时间mbjcgjjk1#
Put your rows into groups first, by
COUNT
ing how many times0
has been in the dataset prior, and then you can use aROW_NUMBER
on that group. You'll need to use couple ofCASE
expressions as well to put0
in the right place.: