File tree Expand file tree Collapse file tree 1 file changed +12
-3
lines changed Expand file tree Collapse file tree 1 file changed +12
-3
lines changed Original file line number Diff line number Diff line change 1
1
# Year-on-year percentage difference
2
-
2
+ To explore this example with some demo data, head [ here ] ( https://count.co/n/7I6eHGEwxX3?vm=e ) .
3
3
4
4
# Description
5
5
Calculating the year-on-year change of a quantity typically requires a few steps:
@@ -46,7 +46,11 @@ select
46
46
from spotify .spotify_daily_tracks
47
47
group by 1 ,3
48
48
```
49
-
49
+ | year | sum_streams | artist |
50
+ | --- | ----------- | ---- |
51
+ | 2020-01-01 | 115372043 | CJ |
52
+ | 2021-01-01 | 179284925 | CJ |
53
+ | ... | ... | ... |
50
54
``` sql
51
55
-- with_perc_diff
52
56
select
59
63
from raw
60
64
order by artist, year desc
61
65
)
62
- ```
66
+ ```
67
+ | year | sum_streams | artist | last_year_total | perc_diff |
68
+ | --- | ----------- | ---- | ---- | ----- |
69
+ | 2020-01-01 | 115372043 | CJ | NULL | NULL |
70
+ | 2021-01-01 | 179284925 | CJ | 115372043 | 55.397200515899684 |
71
+ | ... | ... | ... | ... | .... |
You can’t perform that action at this time.
0 commit comments