Trend previous month metric


#1

Hello guys, I have a trend showing the price of properties through time, i need to add in the same trend the same metric but 1 month before, to compare with the previous month, is it possible?


#2

Actually you can use the Time offset metric, this metric needs a filter to be activated, so you will have available when this filter is applied, here is an example of how to use it:

const saletime = cf.Attribute('saletime')
                        .func('DAY')
                        .limit(100)
                        .sort('asc', 'saletime')
// Filter that triggers the comparative
const filter = cf.Filter('saletime')
                    .between('2008-05-01 00:00:00', '2008-05-31 23:59:59')
// The metrics
const price = cf.Metric('pricepaid', 'sum')
// the time offset metric
const priceComp = cf.CompareMetric('pricepaid', 'sum')
                    .using('saletime') // when this filter is applied the metric will be showed in the trend
                    .with('-1 day')
                    .label('Pricepaid 1 month before');

cf.provider('Elasticsearch')
    .source('ticket_sales')
    .groupby(saletime)
    .metrics(price, priceComp)
    .graph('Multimetric Trend')
    .filter(filter)
    .element('my-trend')
    .execute()

#3

It was easy, for now everything seems to work very well, thank you so much.