Forum Discussion
Trend line values
- 5 years ago
Hi jthomson ,
The trend line calulation formula by DAX is like this:
Linear regression = VAR Known = FILTER ( SELECTCOLUMNS ( ALLSELECTED ( 'Table'[Date] ), "Known[X]", 'Table'[Date], "Known[Y]", CALCULATE ( SUM ( 'Table'[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] * Known[X] ) 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 * Sum_X ) VAR Intercept = Average_Y - Slope * Average_X RETURN SUMX ( DISTINCT ( 'Table'[Date] ), Intercept + Slope * 'Table'[Date] )It will be the same as the trend line in the Analysis pane:
Attached a sample file in the below, hopes to help you.
In addtion, this blog introduces the calculation logic in details that you can refer: Simple linear regression in DAX
Similiar issue: DAX to create a Trend line?
Best Regards,
Community Support Team _ Yingjie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi jthomson ,
The trend line calulation formula by DAX is like this:
Linear regression =
VAR Known =
FILTER (
SELECTCOLUMNS (
ALLSELECTED ( 'Table'[Date] ),
"Known[X]", 'Table'[Date],
"Known[Y]", CALCULATE ( SUM ( 'Table'[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] * Known[X] )
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 * Sum_X
)
VAR Intercept = Average_Y - Slope * Average_X
RETURN
SUMX ( DISTINCT ( 'Table'[Date] ), Intercept + Slope * 'Table'[Date] )
It will be the same as the trend line in the Analysis pane:
Attached a sample file in the below, hopes to help you.
In addtion, this blog introduces the calculation logic in details that you can refer: Simple linear regression in DAX
Similiar issue: DAX to create a Trend line?
Best Regards,
Community Support Team _ Yingjie Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Thanks for this, looks scary but very fast to implement.