Forum Discussion
Formula for trendline
I am using the October download of PBI.
I can add a trendline for scattered plot and a line chart.
However, I cannot find the option to add the formula (just like in Excel).
Any idea?
Thanks,
Tamir
- Anonymous9 years ago
Someone lese asked for it in May - see the comments on https://ideas.powerbi.com/forums/265200-power-bi-ideas/suggestions/6998768-ability-to-add-trend-line-to-charts
You can likely do it in R until/if that feature is implemented in native Power BI visuals - e.g. http://stackoverflow.com/questions/24882209/how-to-get-trendline-equations-in-r
Hi there,
this function replicates the Excel-Trend-function, just without the possiblity to define your own slope and intercept:
(YList as list, NoOfIntervalls as number) => let Source = Table.FromColumns({YList}), xAxis = Table.AddIndexColumn(Source, "Index", 1, 1), Rename1 = Table.RenameColumns(xAxis,{{"Column1", "y"}, {"Index", "x"}}), AvgX = List.Average(Rename1[x]), AvgY = List.Average(Rename1[y]), x = Table.AddColumn(Rename1, "xX", each [x]-List.Average(Rename1[x])), y = Table.AddColumn(x, "yY", each [y]-List.Average(x[y])), xy = Table.AddColumn(y, "xy", each [xX]*[yY]), xXx = Table.AddColumn(xy, "xXx", each [xX]*[xX]), a = List.Sum(xXx[xy])/List.Sum(xXx[xXx]), b = AvgY-(a*AvgX), ListIntervalls = {List.Max(Rename1[x])+1..List.Max(Rename1[x])+NoOfIntervalls}, TableIntervalls = Table.FromList(ListIntervalls, Splitter.SplitByNothing(), null, null, ExtraValues.Error), Rename = Table.RenameColumns(TableIntervalls,{{"Column1", "x"}}), Values = Table.AddColumn(Rename, "y", each [x]*a+b), TREND = Table.Combine({Rename1,Values}) in TREND
19 Replies
- MEhrenmuellerMost Valuable Professional
As far as I know, there is no possibility to specify a formula for the trend line.
In the most recent version there is a possibility to add different kinds of lines. Would one of these fit your needs?
- AnonymousNot applicable
Hi Markus,
I need the formula for predictions...
I posted a suggestion in the Ideas section.
- AnonymousNot applicable
Someone lese asked for it in May - see the comments on https://ideas.powerbi.com/forums/265200-power-bi-ideas/suggestions/6998768-ability-to-add-trend-line-to-charts
You can likely do it in R until/if that feature is implemented in native Power BI visuals - e.g. http://stackoverflow.com/questions/24882209/how-to-get-trendline-equations-in-r
- Gregory_FeltonHelper I
This is simple linear regression. Also, I did not figure this out, but it has been so long that I don't remember where I got it. When I find the guy's name, I'll credit him here.
Just replace your dates (colored blue), and the measure of interest (colored red).
Total Sales Trend =VAR Known =FILTER (SELECTCOLUMNS (CALCULATETABLE ( VALUES ( Dates[Date] ), ALLSELECTED( Dates) ),"Known[X]", Dates[Date],"Known[Y]", [Total Sales]),AND ( NOT ( ISBLANK ( Known[X] ) ), NOT ( ISBLANK ( Known[Y] ) ) ))VAR Count_Items =COUNTROWS ( Known )VAR Sum_X =SUMX ( Known, Known[X] )VAR Sum_X2 =SUMX ( Known, Known[X] ^ 2 )VAR Sum_Y =SUMX ( Known, Known[Y] )VAR Sum_XY =SUMX ( Known, Known[X] * Known[Y] )VAR Average_X =AVERAGEX ( Known, Known[X] )VAR Average_Y =AVERAGEX ( Known, Known[Y] )VAR Slope =DIVIDE (Count_Items * Sum_XY - Sum_X * Sum_Y,Count_Items * Sum_X2 - Sum_X ^ 2)VAR Intercept = Average_Y- Slope * Average_XVAR Result = SUMX ( DISTINCT ( Dates[Date] ),Intercept + Slope * Dates[Date])RETURNIF(SELECTEDVALUE( Dates[Date] ) >= TODAY(),BLANK(),Result)- mc2863Regular Visitor
Thanks for sharing, do you know how we could amend this to be dynamic and account for filtered data either in a table or in an actual visual. We are aggregating data at a product level and would like for the calculated trend to represent the selected product.
- TrevorCAdvocate I
This is a great solution and the code can be found here: https://xxlbi.com/blog/simple-linear-regression-in-dax/
I would really appreciate it if someone could tell me how to display the slope.
- AnonymousNot applicable
Hi Anonymous
As of now, there is no native format option that will give you the regression summary output (Y intercept, slope, R^2, ect.)
You can write some DAX to derive the equation or you can download the 'Craydec Regression Chart' visual from BPI marketplace. This visual will give you the equation (Y= MX + B), R^2, and other regression output data.
Obviously, you can also export your data set to Excel to do the complete regression analysis (P-value, T-test, F-score, std error, and much more).
I hope this helps!
-Eric