I am learning Alteryx and trying to figure out how to count the number of rows backwards/upwards it took for a price to beat its previous prices in "n" rows. Set the count to 0 if the Price is less than previous row price.
For sample purposes, I kept few rows but let say i want to look back 250 rows (n) at a time, how can i achieve that in Alteryx? So my lookback limit is 250. Shorter limits are also okay, if anyone has a better solution to solve this problem in alteryx.
I have explained it in the below example in Notes/comments column for the reasoning of the expected behavior in Notes/Comments column.
example:
| Date | Price | Expected output | Notes/Comments |
| 11/12/2022 | 11 | 0 | Why 0? coz no rows above to compare, Hence count is 0 |
| 11/13/2022 | 10 | 0 | Why 0? coz 10 < 11 (previous price), hence count is 0 |
| 11/14/2022 | 13 | 2 | Why 2? coz 13 > 10 (Previous price) and 13 > 11 (Previous to previous price), hence count is 2 |
| 11/15/2022 | 11 | 0 | Why 0? coz 11<13, hence count is 0 |
| 11/16/2022 | 14 | 4 | Why 4? coz 14>11, 14>13, 14>10, 14>11, Hence count is 4 |
| 11/17/2022 | 12 | 0 | Why 0? coz 12<14, hence count is 0 |
| 11/18/2022 | 16 | 6 | Why 6? coz 16>12, 16>14, 16>11, 16>13, 16>10, 16>11 |
| 11/19/2022 | 17 | 7 | Why 7? coz 17> 16, 17>12, 17>14, 17>11, 17>13, 17>10, 17>11 |
| 11/20/2022 | 13 | 0 | Why 0? coz 13<17, hence count is 0 |