Is it possible to create a trendline like in excel...
# gooddata-cloud
f
Is it possible to create a trendline like in excel? I've tried using RSQ function, but it requires 2 inputs, and I only have 1 aside from the date. I would like the create the red line in the attached picture
m
Hi Filip, please see the following documentation that I hope will help you with this: https://www.gooddata.com/developers/cloud-native/doc/1.1/analytics/maql/statistic/forecast/
f
@Michael Ullock I tried but my GD says that FORECAST function doesn't exist.
m
Ah, my apologies - I just checked the article and I see it’s documentation is for an older version of GoodData, and it seems that this function has since been removed 😕 Please let me check this and get back to you asap
Perhaps the “Combo chart” would work for you? https://www.gooddata.com/developers/cloud-native/doc/cloud/create-visualizations/visualization-types/combo-charts/ Combo charts combine two types of charts - column, area, or line - into a single visualization. You can create a separate AVG metric for the line visualization
Regarding the FORECAST function, it seems that this should not have been added to our Cloud documentation in the first place, as it never was an available function in Cloud. My apologies once again for providing that misleading article previously
p
🎉 New note created.
f
@Michael Ullock That doensn't help since what's plotted on the above line graph is an
AVG(fact)
, so doing a sum & avg in combo chart wouldn't work (also this metric can only every be averaged - summing it would be nonsensical). I noticed there's an
intercept
function, but I can't find documentation on it. Maybe there's also a
gradient
function?
j
The FORECAST function is not available in GD Cloud (yet). Workaround is possible using MAQL but it is rather complex (see article about linear regression). You can use following metrics to plot a trendline if you have Metric 1 which has values defined for each day: Beta
Copy code
SELECT  CORREL((SELECT {metric/metric_1} BY {label/date.day}), (SELECT RUNSUM(SIGN({metric/metric_1})) BY {label/date.day} ))
* STDEV( SELECT {metric/metric_1} BY {label/date.day})
/ STDEV(SELECT RUNSUM(SIGN({metric/metric_1})) BY {label/date.day}) 
BY ALL OTHER
Alpha
Copy code
SELECT AVG(SELECT {metric/metric_1} BY {label/date.day}) 
- ({metric/beta} * AVG(SELECT RUNSUM(SIGN({metric/metric_1})) BY {label/date.day}))
BY ALL OTHER
Trendline
Copy code
SELECT {metric/alpha} + {metric/beta} * RUNSUM(SIGN({metric/metric_1}))
or as one MAQL definition Trendline
Copy code
SELECT (SELECT AVG(SELECT {metric/metric_1} BY {label/date.day}) - 
  ((SELECT  CORREL((SELECT {metric/metric_1} BY {label/date.day}),
(SELECT RUNSUM(SIGN({metric/metric_1})) BY {label/date.day} ))
* STDEV( SELECT {metric/metric_1} BY {label/date.day})/
STDEV(SELECT RUNSUM(SIGN({metric/metric_1})) BY {label/date.day}) BY ALL OTHER) * AVG(SELECT RUNSUM(SIGN({metric/metric_1})) BY {label/date.day}))
  BY ALL OTHER)  + ( (SELECT  CORREL((SELECT {metric/metric_1} BY {label/date.day}),
(SELECT RUNSUM(SIGN({metric/metric_1})) BY {label/date.day} ))
* STDEV( SELECT {metric/metric_1} BY {label/date.day})/
STDEV(SELECT RUNSUM(SIGN({metric/metric_1})) BY {label/date.day}) BY ALL OTHER)  * RUNSUM(SIGN({metric/metric_1})))
Note that you may need to adjust the definition of metric if you want to aggregate the metric by month or other level of date dimension granularity.
👍 1
f
@Jakub Sterba Thank you, that works quite well.