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
earlenereid
Frequent Visitor

Trend line when x-axis is text field

I would like to add a trendline to a stacked column chart.  The x-axis is a text field which displays the year/month formatted as YYYY-MM.  I am able to add a Constant line, but not a trend line.  Example shown below.

 

This is simple to do in Excel, but I have not found a way to do it in Power BI.  Any help would be much appreciated!

 

Capture.PNG

1 ACCEPTED SOLUTION
mdannemiller
Frequent Visitor

It doesnt appear that you can because power bi doesnt know how to order them chronologically.  I'd make another column which creates a date from that column 

 

NewDate = DATE(LEFT([Date],4), RIGHT([Date],2), 1) or similar which will give you a date which is the first day of each month. 

View solution in original post

3 REPLIES 3
Eric_Zhang
Employee
Employee


@earlenereid wrote:

I would like to add a trendline to a stacked column chart.  The x-axis is a text field which displays the year/month formatted as YYYY-MM.  I am able to add a Constant line, but not a trend line.  Example shown below.

 

This is simple to do in Excel, but I have not found a way to do it in Power BI.  Any help would be much appreciated!

 

Capture.PNG


@earlenereid

You might need a calendar table as below

calendar =
ADDCOLUMNS (
    CALENDAR ( "2017-01-01", "2017-12-31" ),
    "Year-Mon", CONCATENATE (
        CONCATENATE ( YEAR ( [Date] ), "-" ),
        RIGHT ( CONCATENATE ( "0", MONTH ( [Date] ) ), 2 )
    )
)

The a measure as below to calculate the "trend"

diff =
VAR currentVal =
    SUM ( 'Table'[value] )
VAR preMonVal =
    CALCULATE ( SUM ( 'Table'[value] ), PREVIOUSMONTH ( 'calendar'[Date] ) )
RETURN
    ( currentVal - preMonVal )
        / currentVal

Capture.PNG

 

See more details in the attached pbix.

 

mdannemiller
Frequent Visitor

It doesnt appear that you can because power bi doesnt know how to order them chronologically.  I'd make another column which creates a date from that column 

 

NewDate = DATE(LEFT([Date],4), RIGHT([Date],2), 1) or similar which will give you a date which is the first day of each month. 

I was able to create a date column to be used as my x-axis column.  With a few additional adjustments, I can now add a trend line:

 

  • Change x-axis type from Categorical to Continuous
  • Change from Stacked Column chart to Clustered Column

 

There is a remaining issue:

 

My x-axis is only showing labels on every other month.  How do I control that?

 

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.