I am tasked at work to build a report that shows marketing data on campaign level segmented by days. The main challenge is to fulfill the requirement of comparing different data to the same data a week ago. Unfortunately, Excel is not an option (here, the =CALCULATE formula would do the trick in Power Pivot).
I decided to use Google Sheets, with at table structured like this:
Day | Account | Campaign | Cost
2020-03-23 | Acc1 | Camp1 | 12.3
2020-03-22 | Acc1 | Camp2 | 15.3
Now, I added a column 'Cost 1w' that should get the the cost form the same campaign in the same account one week ago. This data then is used in a Pivot to analyse it. The formula for this is
=SUMIFS($D:$D, $A:$A, $A2-7, $B:$B, $B2, $C:$C, $C2)
As this calculation makes Sheets very slow, and I want to automate the way i import the data, I started to use Python to get the data from an API to a Pandas dataframe and write it into the sheet. I only have no idea about how to calculate the 'Cost 1w' column in the dataframe, even though I tried the solutions I found online. Any help would be appreciated.