Forum Discussion
DAX Trend Line with Month Year column
Hi,
Is there a way to add a trend line using a month year column (mmmm yyyy). The Month Year column is calculated from the SAMPLE DATE column.
The below is the query to calculate the trend -
Thanks
Hi yaman123 ,
This post will help you: Use Custom DAX to create a Linear Regression Trendline with a Dynamic Date Hierarchy in Power BI - Microsoft Tech Community.
It create a trend line by week-year. And here is the corresponding video:
Best Regards,
Icey
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
6 Replies
- johnt75
Super User
Set up a date table linked to the sample date column and then in your measure definition replace every mention of the sample date column with the column from your date table which you are using in the visual - e.g. 'Date'[Year month].
Its important that the column used in the trend line measure matches exactly with the column you are using as the axis
- yaman123
Post Partisan
hI johnt75
I get the below error when changing the measure definitions and adding the new column as the X axis?
My new measure -
Linear regression =VAR Known =FILTER (SELECTCOLUMNS (ALLSELECTED ( 'Date Table'[Date Month Year] ),"Known[X]", 'Date Table'[Date Month Year],"Known[Y]", [Count of Member Code]),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_XRETURNSUMX ( DISTINCT ( 'Date Table'[Date Month Year]), Intercept + Slope * 'Date Table'[Date Month Year])- johnt75
Super User
Try changing the Date Month Year column to be of type date. If you store it as 01/mm/yyyy then you can set the format string to display just month and year, it should give the results you're looking for
- Icey
Community Support
Hi yaman123 ,
This post will help you: Use Custom DAX to create a Linear Regression Trendline with a Dynamic Date Hierarchy in Power BI - Microsoft Tech Community.
It create a trend line by week-year. And here is the corresponding video:
Best Regards,
Icey
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.