Forum Discussion
Help with Linear Trend line ?
Hi,
Help me to get the trend line like below .
I have used
I have attached my sample pbix file.
https://github.com/suvechha/samplepbi/blob/main/sampleTrend.pbix
Thanks
14 Replies
- parry2kSuper User
ashmitp869 maybe try to change currentx value to this:
VAR CurrentX = RANKX(ALL('Date'[Year-Month Code], 'Date'[MonthYear]), CALCULATE( MAX('Date'[Year-Month Code])), , DESC) - Ritaf1983Super User
Hi ashmitp869
From what I see, the trend lines are much lower than the actual values, which indicates a calculation issue.
This usually happens because the formula removes filters from Month-Year, but columns that are indirectly related to that field (like a column used for sorting) still participate in the query behind the scenes.
So even if the visual doesn’t directly use the month column, it still filters the calculation context.
That’s why when you want to manipulate context involving Month-Year, it’s better either to include the related columns as well, or to operate at the Calendar table level — for example, like in my formula below:Trend for Goals Scored =
VAR Known =
FILTER (
SELECTCOLUMNS (
ALLSELECTED ( 'Calendar' ),
"KnownX", 'Calendar'[yy-mm],
"KnownY", [Sales]
),
NOT ( ISBLANK ( [KnownX] ) )
&& NOT ( ISBLANK ( [KnownY] ) )
)
VAR SlopeIntercept =
LINESTX ( Known, [KnownY], [KnownX] )
VAR Slope =
SELECTCOLUMNS ( SlopeIntercept, "Slope", [Slope1] )
VAR Intercept =
SELECTCOLUMNS ( SlopeIntercept, "Intercept", [Intercept] )
RETURN
SUMX (
DISTINCT ( 'Calendar'[yy-mm] ),
Intercept + Slope * 'Calendar'[yy-mm]
)The pbix with the example is attachd
If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly
- ashmitp869Responsive Resident
Hi Ritaf1983
I have used your Trend for Goals Scored, but still getting same result.
Will you have a look on the sample file.
https://github.com/suvechha/samplepbi/blob/main/sampleTrend.pbix
The Excel provide Linear Trendline likev-tejrama still needs help as not getting the correct result.
- v-tejramaCommunity Support
Hi ashmitp869 ,
We kindly suggest raising a support ticket with the partners group: Power BI Partners | Microsoft Power Platform as they will be able to investigate the matter in detail and provide deeper assistance. I also tried several workarounds on my side, but I was unable to change the measure in the PBIX file you provided, so involving the supporting partners group would be the best next step.
Thank you.
- v-tejramaCommunity Support
Hi ashmitp869 ,
Thank you Ritaf1983 and parry2k for the response provided!
Has your issue been resolved? If the response provided by the community member addressed your query, could you please confirm? It helps us ensure that the solutions provided are effective and beneficial for everyone.Thank you.