Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago

New table with distinct ID + calculated columns on multiple conditions

Hello

 

I have a table with all my orders, linked to customers with a date and a channel

Here's a sample

CustomerIDOrderIDDateChannel
A1101/05/2023M
A1231/03/2022M
A1319/12/2022G
A2419/07/2023G
A2501/07/2020G
A3601/06/2023M
A4728/02/2021M
A4815/12/2020G
A4920/05/2022G
A41015/07/2021G
A41107/07/2023G
A41203/04/2021M

 

 

I'd like to create a new table that calculate number of orders per year per customer for a specific channel.

Let's take the example of channel G, I'd like to create the following table

CustomerIDNN+1N+2N+3N+4
A111   
A21   1
A41 12 

 

N = Number of orders in the last 365 days of the customer for the channel G

N+1 = Number of orders between 366 and 730 days compare to today of the customer for the channel G

 

I guess it is not that complicated as it seems something classical to do, but I don't find the right way to do it.

 

Thanks for your help

Maxime