
1. Re: Calculation of slope of trend line
Jim Wahl Sep 14, 2017 5:35 AM (in response to Ale Crippa)The easiest starting point is to use the builtin trend line. See screen shot below.
If you want to show the slope or correlation in the title or tooltip, you can calculate these manually.
r = correlation:
r order date and count =
WINDOW_CORR(ATTR(INT([Order Date])), COUNT([Order ID]))
slope = r * StdDev y / StdDev x =
[r order date and count] * WINDOW_STDEV(COUNT([Order ID])) /
WINDOW_STDEV(ATTR(INT([Order Date])))
Note that WINDOW_XXX are table calculations, which are "aggregates of aggregates". The aggregates, in this case, are COUNT(Order ID) and ATTR(INT(Order Date)). The date is converted to an int and then the ATTR() is used to aggregate it. ATTR() is sort of a helper aggregation where Order Date will be returned if there is only one value of order date for the mark.
For this to work, you need order date in the view. Most likely it'll be your xaxis as an "exact date" pill. If you want to aggregate at a different date level (week, month, quarter), you'd need to use the DATETRUNC(period, [Order Date]) function in both the calculated fields and the pills in the view. The period can be parameterized for week, month, quarter, ...
Jim

2. Re: Calculation of slope of trend line
Jim Wahl Sep 14, 2017 5:41 AM (in response to Jim Wahl)And if you just want the slope, you could use cov / var.
//slope of trend line = cov(x,y) / var(x)
WINDOW_COVAR(SUM([Profit]), SUM([Sales])) / WINDOW_VAR(SUM([Profit]))
See: Covariance, Trend Lines, Correlation Coefficient R and RSquared