OpenBI Docs Buy

TRENDLINE OpenBI

Trend lines or curves of y on x (linear, polynomial, log, exp, power) with their confidence and prediction bands and R², as R's lm.

Group: Statistics. OpenBI’s own: DAX has no function of this name.

Syntax

TRENDLINE ( <table>, <y>, <x> [, <models>] [, <level>] [, <points>] )
ParameterTypeDescription
tableTableThe rows to fit the curves to.
yExpression
evaluated for each row
The value to explain, for each row.
xExpression
evaluated for each row
The value it is plotted against, for each row.
modelsText
optional
Which curves to fit, at most eight, separated by spaces or commas: "linear" (the default), "quadratic" and "cubic", "poly:N" for a polynomial of degree N from 1 to 6, "log", "exp" and "power".
levelNumber
optional
The confidence level of the bands, between 0 and 1; 0.95 when left out.
pointsWhole number
optional
At how many values of x, evenly from the smallest to the largest, each curve is given: 2 to 10,000; 100 when left out.

Returns

Table. A row a point of each curve: Model, X, Fit, Lower and Upper (the band for the curve itself), Prediction lower and Prediction upper (the band for one new value), R squared and Observations.

Remarks

  • Select and order the columns with SELECTCOLUMNS, as the examples do: the curve between its bands reads well. The bands are those of R's predict with lm: the confidence band says where the curve itself may run, the prediction band, always wider, where a single new value may fall.
  • log fits y against ln x, exp ln y against x, and power ln y against ln x. exp and power give the fit and the bands back in y's units; their R squared is that of the fit on the logarithms.
  • log and power need every x above 0; exp and power every y above 0.
  • A row with a blank x or y is left out. A curve needs more rows than it has coefficients: a line three, a cubic five.

Compared with DAX

An OpenBI function: DAX has none like it, so a measure or query that uses it works in OpenBI only, not in Power BI or Analysis Services.

Examples

A line through eight weeks, at three points

EVALUATE
VAR Weeks =
    DATATABLE (
        "Week", INTEGER, "Liters", INTEGER,
        { { 1, 410 }, { 2, 435 }, { 3, 470 }, { 4, 462 }, { 5, 505 }, { 6, 530 }, { 7, 528 }, { 8, 571 } }
    )
RETURN
    SELECTCOLUMNS (
        TRENDLINE ( Weeks, [Liters], [Week], "linear", 0.95, 3 ),
        "Model", [Model], "X", [X],
        "Prediction lower", [Prediction lower], "Lower", [Lower], "Fit", [Fit], "Upper", [Upper],
        "Prediction upper", [Prediction upper], "R squared", [R squared]
    )
ModelXPrediction lowerLowerFitUpperPrediction upperR squared
linear1379.194483442796394.780803004987413.25431.719196995013447.3055165572040.959841505851749
linear4.5458.527012560475478.759004186825488.875498.990995813175519.2229874395250.959841505851749
linear8530.444483442796546.030803004987564.5582.969196995013598.5555165572040.959841505851749

Three curves compared at the ends

EVALUATE
VAR Weeks =
    DATATABLE (
        "Week", INTEGER, "Liters", INTEGER,
        { { 1, 410 }, { 2, 435 }, { 3, 470 }, { 4, 462 }, { 5, 505 }, { 6, 530 }, { 7, 528 }, { 8, 571 } }
    )
RETURN
    SELECTCOLUMNS (
        TRENDLINE ( Weeks, [Liters], [Week], "linear quadratic exp", 0.95, 2 ),
        "Model", [Model], "X", [X],
        "Prediction lower", [Prediction lower], "Lower", [Lower], "Fit", [Fit], "Upper", [Upper],
        "Prediction upper", [Prediction upper], "R squared", [R squared]
    )
ModelXPrediction lowerLowerFitUpperPrediction upperR squared
linear1379.194483442796394.780803004987413.25431.719196995013447.3055165572040.959841505851749
linear8530.444483442796546.030803004987564.5582.969196995013598.5555165572040.959841505851749
quadratic1370.008403100528385.33164816336413.041666666667440.751685169973456.0749302328050.959848790125788
quadratic8521.258403100528536.58164816336564.291666666667592.001685169973607.3249302328050.959848790125788
exp1387.462118347241400.332176648324416.137246899766432.566299584358446.934551940180.958421116887303
exp8529.015778680446546.587725953258568.166949186309590.598117776402610.2156025532750.958421116887303

LINESTX, LINEST, CORREL, DECOMPOSE.

Last updated · OpenBI Studio 0.3.74