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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
alexcatala
Helper IV
Helper IV

Trendline in a Text date(Year_month) graph

Hi,

 

How can I add a trendline into a graph where the Axis are the dates(Year and month), but is established as text(unable to change it to date) and could add the trendline?

 

this is my calendar date:

 
d_DateTable =
VAR EarliestDate =
MIN ( MIN ( f_DailySales[Date] ), MIN ( f_Employees[EmpLeavDate] ) )
VAR LatestDate =
MAX ( MAX ( f_DailySales[Date] ), MAX ( f_Employees[EmpJoinDate] ) )
VAR StartDate =
DATE ( YEAR ( EarliestDate ), 1, 1 )
VAR EndDate =
DATE ( YEAR ( LatestDate ), MONTH ( LatestDate ) + 1, 1 ) - 1
RETURN
ADDCOLUMNS (
CALENDAR ( StartDate, EndDate ),
"Year", YEAR ( [Date] ),
"Quarter", QUARTER ( [Date] ),
"Month", MONTH ( [Date] ),
"Week", WEEKNUM ( [Date], 1 ),
"Year_Quarter", YEAR ( [Date] ) & "_Q"
& QUARTER ( [Date] ),
"Year_Month", YEAR ( [Date] ) & "_M"
& FORMAT ( MONTH ( [Date] ), "00" ),
"Year_WeekNum", YEAR ( [Date] ) & "_W"
& FORMAT ( WEEKNUM ( [Date], 1 ), "00" ),
"Day_Week",WEEKDAY([Date],2),
"Year_WeekNum (Skechers)",
VAR SkWeek =
LOOKUPVALUE ( d_SkechersWeeks[Skechers Week], d_SkechersWeeks[Date], [Date] )
VAR LastSkDay =
MAX ( d_SkechersWeeks[Date] )
VAR WeekNum_Bias =
VALUE (
RIGHT (
LOOKUPVALUE ( d_SkechersWeeks[Skechers Week], d_SkechersWeeks[Date], LastSkDay ),
1
)
)
- WEEKNUM ( LastSkDay, 1 ) //-1
VAR AdjustedWeekNum =
YEAR ( [Date] ) & "_W"
& FORMAT ( WEEKNUM ( [Date], 1 ) + WeekNum_Bias, "00" )
RETURN
IF ( [Date] > LastSkDay, AdjustedWeekNum, SkWeek )
)
 
As I want to obtain the values from each month and year, I created the date(Year_month) to could minimise the amount of data, but due as it is established as Text cant add a trendline.
 
Screenshot 2020-10-28 162420.png
 
Any suggestion?
 
Thanks
5 REPLIES 5
v-eqin-msft
Community Support
Community Support

Hi @alexcatala ,

 

It seems like as long as the type of Year-month column is Date, it could be solved...

How about copying the original Date column and format it as yyyy-mm  directly in Column Tools tab like this:
11.2.5.1.PNG

Did I answer your question ? Please mark my reply as solution. Thank you very much.
If not, please upload some insensitive data samples and expected output.

 

Best Regards,
Eyelyn Qin

amitchandak
Super User
Super User

@alexcatala , In case you need a continuous line, you have to plot it on the date.  Maybe you can try on YYYYMM (Data type Int)

@amitchandak 

 

Do you mean change the current Year_month? or make an extra one?

If so what would you think it will be the best formula.

"Year_Month", YEAR ( [Date] ) & "_M"
& FORMAT ( MONTH ( [Date] ), "00" ),
 
Thanks

@v-lionel-msft 

 

Do you mind to have a look at this issue?

 

As mentioned above I cant add a trendline as the date I used as the axis is with the format (TEXT). I use Year and month, but cant is saved as date as it is not valid. 

 

To be able to add a trendline it has to change the x type from categorical into continuous. Unfortunately, it pops this message and can't add the continuous type.

 

Any suggestion?

 

Thanks for your time!

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.