Forum Discussion

Kedar_Pande's avatar
Kedar_Pande
Super User
1 year ago
Solved

Dynamically Change Line Colors Based on a Threshold

I have a line chart showing "Sales Growth" over time, and I want to change the line color based on a threshold value (e.g., if growth is above 10%, the line should turn green; if below 10%, it should turn red).

Is there a way to apply this dynamic color change directly to the line chart in Power BI without splitting the data into multiple lines? What’s the best way to implement this?

 

Example Data:

Date Sales         Growth
Jan 2024               12%
Feb 2024                8%
Mar 2024              15%

7 Replies

    • Kedar_Pande's avatar
      Kedar_Pande
      Super User

      Thanks for the reply Arul .

      This workaround can be used as changing colours on the line chart is not supported currently. 

  • In Power BI, dynamic color changes based on a threshold for line charts are not directly supported in a single line chart visual. However, you can work around this limitation using the conditional formatting feature in combination with measures to achieve the desired effect. Here’s how you can implement it:

    Step-by-Step Approach:

    Create a Measure to Set Dynamic Color: You'll need to create a new measure to define the color logic based on your threshold (in this case, 10%).

    Go to the Modeling tab and create a new measure with the following DAX formula:

    LineColor = IF( SELECTEDVALUE('SalesData'[Growth]) >= 10%, "#00FF00", // Green if above or equal to 10% "#FF0000" // Red if below 10% )

    Add a New Line Chart: Add your existing line chart using Date for the axis and Growth for the values.

    1. Conditional Formatting on the Line Chart: Unfortunately, Power BI does not yet support direct conditional formatting for line chart lines. So, the approach would be to split the data based on the threshold.
    2. You can use an approach like splitting your data into two measures for plotting two lines, one for growth above the threshold and one for below.
    3. Alternatively, if this approach doesn’t fit your needs, you can submit an idea for dynamic line chart formatting on the Power BI community page. The Power BI community is constantly improving based on user feedback.

    Did I answer your question? Mark my post as a solution! Appreciate your Kudos !!

     

    Let's Connect on LinkedIn: https://www.linkedin.com/in/anmol-malviya/?originalSubdomain=in

     

    • Kedar_Pande's avatar
      Kedar_Pande
      Super User

      I need an exact solution to display the dynamic colour changes based on thresholds on a single line.

      I will submit the idea.

      Thanks

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Kedar_Pande 

     

    Currently Power BI's line charts do not support dynamic color changes based on thresholds on a single line.

    As BIswajit_Das and Arul mentioned in their replies, it is currently possible to have a conditionally formatted bar chart and then change it to a line chart to achieve a similar effect.

     

    If this alternative is helpful to you, please consider accepting their replies as a solution.
    Or you can submit an idea at ideas.

     

    Thank you for your understanding.

     

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

    • Kedar_Pande's avatar
      Kedar_Pande
      Super User

      I’ve already tried the bar chart workaround, but I need an exact solution to display the dynamic color changes based on thresholds on a single line.