I have a pivot where weeks are displayed as columns and revenue is the value. The user picks the week numbers to compare revenue, so for instance week 7 and week 8 can be displayed at the same time. I want to add a column that calculates the difference between the chosen weeks. They change every week, so this week i might choose 7 and 8 but then next week 8 and 9. How do I do that in Looker?
Let's assume your data looks like this:
Week (pivoted dimension) | Week 1 | Week 2 | Week 3 |
Revenue (measure) | 400 | 300 | 500 |
To compare revenue values between different pivot values, you'll want to use table calculations. I'd recommend either pivot_index or pivot_offset. Let's go over the pros and cons of each.
If you were to use pivot_index:
Week (pivoted dimension) | Week 1 | Week 2 | pivot_offset calc |
Revenue (measure) | 400 | 300 | -100 |
If you were to use pivot_offset:
Week (pivoted dimension) | Week 1 | Week 1 - Week 0 | Week 2 | Week 2 - Week 1 | Week 3 | Week 3 - Week 2 |
Revenue (measure) | 400 | null | 300 | -100 | 500 | 200 |
I hope this helps as a starting point!
Note that my answer above relies on Looker table calculations, which aren't available in Looker Studio. I don't think Studio has any way to look across pivot columns 🤔
Okay, I have another idea for Looker Studio. What if we don't use a pivot table at all?
Here's my idea. We create one metric for Week A, one metric for Week B, and one metric that calculates the delta. First, to illustrate my point, I'll show how you'd do this with static weeks.
revenue_week_1 | revenue_week_2 | delta |
400 | 300 | -100 |
Now let's introduce some user input here. Since we are just using integers for the week numbers, we can create two integer parameters weekA and weekB that users can select from. Then we'll create similar fields to before, but instead of hardcoding the values "1" and "2", now we insert the parameter names "weekA" and "weekB". In the end, you'll get something like this image: