Norway


I’m trying to change from the following format :

id yrmo sales

1 . 01 . 200

1 . 201801 . 250

2 . 201801 . 150

2 . 201802 . 160

3 . 201802 . 180

3 . 201802 . 180

3 . 2018 . 300

to the following format

id . 201801_sales . 201802_sales . 201803_sales

1 . 450 0 0

2. 150 160 0

3. 0 360 . 300

I’ve been pivoting with case when for each of the columns that i’m trying to create (sum(case when…) as 2018_01_sales). This works fine for a few columns. However I’m about to take pretty big timeframe due to which I’ll be needing about 48 columns. Is there a better way than using a case when for each column? Thanks.



Source link

No tags for this post.

LEAVE A REPLY

Please enter your comment!
Please enter your name here