1.21 Order-based computation: find the continuous interval having the specified feature
Find records where sales amounts rise for at least three days based on the following daily sales table.
Date | Sales |
---|---|
2022-01-01 00:00:00 | 98.0000 |
2022-01-02 00:00:00 | 174.0000 |
2022-01-03 00:00:00 | 168.0000 |
2022-01-04 00:00:00 | 167.4000 |
2022-01-05 00:00:00 | 1696.0000 |
… | … |
SPL script:
A | |
---|---|
1 | =T(“DailySales.xls”) |
2 | =0 |
3 | =A1.group@o(if(Sales>Sales[-1], A2,A2=A2+1)).select(~.len()>=3).conj() |
A3 Take A2 as a temporary value, and it remains unchanged when sales increases and adds 1 to it when sales decreases; group table by the temporary value to put records with continuously rising sales in same group.
Execution result:
Date | Sales |
---|---|
2022-01-10 | 95.76 |
2022-01-11 | 222.3 |
2022-01-12 | 2462.4 |
2022-01-28 | 86.4 |
2022-01-29 | 156 |
2022-01-30 | 608 |
SPL Official Website 👉 https://www.scudata.com
SPL Feedback and Help 👉 https://www.reddit.com/r/esProc_SPL
SPL Learning Material 👉 https://c.scudata.com
SPL Source Code and Package 👉 https://github.com/SPLWare/esProc
Discord 👉 https://discord.gg/cFTcUNs7
Youtube 👉 https://www.youtube.com/@esProc_SPL