Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Anonymous
Not applicable

Manually add a Trend Line using Categorical X-Axis

Hi Team,

 

I need help with adding a correct formula for a manual trend line because we need to use Categorical as the X-Axis since the Analytics only accepts Continuous to add a Trend Line.

 

So I used the logic located here - https://techcommunity.microsoft.com/t5/healthcare-and-life-sciences/use-custom-dax-to-create-a-linea...

 

It works for the most part but I'm seeing inaccuracies to the line when selecting a country. See examples below:

NOTE: The 2 graphs up top is the manual trend line and the 2 graphs in the bottom is the power BI generated one.

 

swaggerboy69_0-1656431684600.png

 

swaggerboy69_1-1656431764949.png

 

swaggerboy69_2-1656431802115.png

 

swaggerboy69_3-1656431853202.png

 


Can anyone help out and suggest a modification of the code.

 

I'm using the code below:

 

TLMCall RunCount(X) =
VAR MinDate = CALCULATE(MIN('Return to Office'[ReportMonth]),ALLSELECTED('Return to Office'[ReportMonth]))
RETURN
SWITCH(TRUE(),
ISFILTERED('Return to Office'[ReportMonth]),CALCULATE(DISTINCTCOUNT('Return to Office'[ReportMonth]),FILTER(ALL('Return to Office'[ReportMonth]),'Return to Office'[ReportMonth] <= MAX('Return to Office'[ReportMonth]) && 'Return to Office'[ReportMonth] >= MinDate)),
BLANK()
)

==================================================================================

TLMCall i380 Avg = AVERAGE('Return to Office'[InternalCall])

==================================================================================

TLMCall i380 Avg Prev =
VAR WeekIndexPrev = MAX('Return to Office'[ReportMonth]) - 1
RETURN
SWITCH(TRUE(),
[TL RunCount(X)] < 1,BLANK(),
ISFILTERED('Return to Office'[ReportMonth]),CALCULATE([TL i380 Avg],PREVIOUSMONTH('Return to Office'[ReportMonth])),
BLANK())

==================================================================================

TLMCall Rise =
SWITCH(TRUE(),
[TL RunCount(X)] <= 1, BLANK(),
[TL i380 Avg] - [TL i380 Avg Prev])

==================================================================================

TLMCall Avg Rise (M) =
SWITCH(TRUE(),
[TL RunCount(X)] <1, BLANK(),
ISFILTERED('Return to Office'[ReportMonth]),CALCULATE(AVERAGEX(SUMMARIZE('Return to Office','Return to Office'[ReportMonth]),[TL Rise]),ALLSELECTED('Return to Office'[ReportMonth])),
BLANK()
)

==================================================================================

TLMCall Y Intercept (B) =
SWITCH(TRUE(),
[TL RunCount(X)] < 1, BLANK(),
ISFILTERED('Return to Office'[ReportMonth]), CALCULATE(AVERAGEX(SUMMARIZE('Return to Office','Return to Office'[ReportMonth]),([TL i380 Avg] - ([TL Avg Rise (M)] * [TL RunCount(X)]))),ALLSELECTED('Return to Office'[ReportMonth])),
BLANK()
)

==================================================================================

TLMCall Regression (Y) = ([TL Avg Rise (M)] * [TL RunCount(X)]) + [TL Y Intercept (B)]

 

 

 

1 REPLY 1
Anonymous
Not applicable

Hi @Anonymous ,

 

I think your calculation is based on your data model, please share a easy sample file without sensitive data with me and show a screenshot with the result you want. This will make it easier for me to find the solution.

 

Best Regards,
Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors