Hi,
I have a pretty tricky situation which I’d be interested in seeing if it’s familiar to anyone. I have a table with the raw data has the form:
week, metric, value
20190415, ‘Signups’ 15443
20190415, ‘Sales’, 28474
20190408, ‘Signups’ 19393
20190408, ‘Sales’, 39494
etc. (in reality many more metrics)
I have created some calculated fields to get current quarter, and weeks since beginning of quarter:
week, metric, value, current_q, weeks_since_beginning_q
20190415, ‘Signups’ 15443, 20190401, 2
20190415, ‘Sales’, 28474, 20190401, 2
20190408, ‘Signups’ 19393, 20190401, 1
20190408, ‘Sales’, 39494, 20190401, 1
Now what I want to do is get Quarter to Date numbers for each metric, so something like sum(offset_list(value,0, weeks_since_beginning_q)), but only for rows where metric matches the current row’s metric:
week, metric, value, current_q, weeks_since_beginning_q, qtd
20190415, ‘Signups’ 15443, 20190401, 2, 34836 (15443 + 19393)
20190415, ‘Sales’, 28474, 20190401, 2, 67968 (28474 + 39494)
20190408, ‘Signups’ 19393, 20190401, 1, 19393
20190408, ‘Sales’, 39494, 20190401, 1, 19393
Does anyone know of some intricate combination of ifs/lookups/offsets that would accomplish this? I’ve really tried but can’t seem to be able to work it out. 😦 This looks to be aiming at something similar but seems to have been handled offline: Summing rows with a specific condition
If there was an interval parameter in offset_list that would work here too as there’ll always be a constant number of metrics, but doesn’t seem like there is. Any ideas would be greatly appreciated. Thanks!
/Petter