I have a possibly weird use case that I’ve been trying to figure out how to implement. I would like to create a concept of ‘open’ on one of my tables that I could use to aggregate data by. However, determining this status requires comparing two columns since I want to be able to look back in time to find the rows that could be considered ‘active’ in a previous time range.
eg:
cube('Order', {
sql: `select * from order`,
measures: {
amountSum: {
sql: `amount`,
type: `sum`,
},
},
dimensions: {
started: {
sql: `started`,
type: `time`,
},
shipped: {
sql: `shipped`,
type: `time`,
},
open: {
sql: `started <= $1 AND $2 <= shipped`,
type: `time`,
},
},
});
Obviously this above example doesn’t work, but hopefully it illustrates what I’m looking for.
I’ve tried using the FILTER_PARAMS
to try defining some custom behaviour for this but unfortunately it seems like the way FILTER_PARAMS
are applied doesn’t allow this:
cube('Order', {
...
open: {
sql: `FILTER_PARAMS.Order.open.filter((start, end) => {
return `started <= ${start} AND ${end} <= shipped`;
}
because the above gets translated to:
SELECT amount_sum
FROM order
WHERE (
(started <= ${start} AND ${end} <= shipped) > ${start}
) AND (
(started <= ${start} AND ${end} <= shipped) < ${end}
);
So either this isn’t how the FILTER_PARAMS are supposed to be used, or there is a bug in how they are applied. If the former, is there any way I can achieve this behaviour of creating a timeDimension based off two columns? If the latter I’d be interested in trying to get this fixed since this would be really useful for me…