avatarIsabelle Bittar

Summary

Isabelle Bittar demonstrates a method for dynamically changing the colors of area or line charts in Power BI by using two identical charts with different colors and applying measures to filter them based on data variation.

Abstract

In the article "How To Dynamically Change Area or Line Chart Colors in Power BI," Isabelle Bittar provides a detailed guide on enhancing Power BI charts with dynamic color changes. Since Power BI lacks native functionality for dynamic color adjustments in line or area charts, Bittar outlines a workaround involving the creation of two charts—one green and one red. By using a measure that filters the charts based on whether the price variation is positive or negative, the appropriate chart color is displayed. This technique involves setting the measure to either 1 (for positive/zero variations) or 0 (for negative variations) and then overlaying the charts to create the illusion of a single, dynamically colored chart. The article also discusses a limitation of this method, where hovering over the secondary chart does not show detailed values, and suggests other use cases for dynamic visibility in Power BI visualizations.

Opinions

  • The author, Isabelle Bittar, views the dynamic color change as a significant enhancement for Power BI charts, effectively representing positive and negative variations.
  • Bittar acknowledges the limitation of the technique, particularly the inability to access detailed values from the secondary chart when it overlays the primary one.
  • The author emphasizes the versatility of using filter pane measures to toggle chart visibility, suggesting its application in various scenarios beyond just color dynamics.
  • Bittar encourages the Power BI community to engage with her content, indicating a commitment to sharing knowledge and fostering community growth.
  • The article reflects the author's opinion that creative solutions, such as overlaying charts with conditional visibility, can significantly improve data visualization and interactivity in Power BI reports.

How To Dynamically Change Area or Line Chart Colors in Power BI

Mastering Visual Insights: A Step-by-Step Guide to Custom Color Dynamics in Power BI Charts

By Isabelle Bittar for KI Data Science

PBIX file available for download at the end of this article.

Introduction

In my last article, Using Time Periods as Slicers to Enhance Power BI Line and Area Charts’ Range, I showed how to dynamically adjust line or area chart axes using a time period slicer. A notable feature in the accompanying images was the color transition of my charts — shifting from green to red based on the stock/asset price fluctuation. This color change effectively represented positive (green) and negative (red) variations.

By Isabelle Bittar for KI Data Science

This technique can be very useful, especially since Power BI does not offer the option to dynamically change the color of lines/areas, unlike its capability with bar charts.

No Native Option to Dynamically Change Line Colors in Power BI Area or Line Charts

How To Achieve This in Power BI

To achieve this, I basically used two charts: 1 green chart and 1 red chart. Both charts were exactly the same, except for their line colors.

Starting Point: Two Area Charts With Different Line Colors

I then created a measure, applied to each chart’s filter pane, that was used to hide or display the area chart. The result of the following measure gave a 0 or 1 depending if the asset’s price variation was null or positive (1) or negative (0).

Chart Variation Display = 
    IF(
        CALCULATE([Price Variation], ALL('Stock Data'[Date]))>=0,
        1,
        0
    )

For the green chart, I set this measure in its filter pane to equal 1

Applying 1 to the Chart Variation Display Filter Measure to the Green Chart

… while for the red chart, I assigned it a value of 0.

Applying 0 to the Chart Variation Display Filter Measure to the Red Chart

Once I clicked on the Apply Filter for the red chart, the chart disappeared as expected (since the variation was positive).

As a final step, I overlayed the charts one on top of each other. I also made sure that the background of both chart was turned off, ensuring that the appropriate color chart was visible depending on the price variation.

Turning Off the Charts’ Background

Limitation

One constraint of this approach is the inability to hover over the secondary chart for detailed values. For instance, if the red chart overlays the green, only the red chart’s values are accessible.

Limitation: Cannot Hover Over The Values of The Green Chart

Other Use Cases for This Technique

This method of toggling chart visibility based on filter pane measures is versatile and applicable in various scenarios. For instance, I applied a similar technique in the following article to safeguard confidential information through context-sensitive visualizations.

Color-Coding Area or Line Charts’ Data Markers

Additionally, an alternative approach involves color-coding data markers of line or area charts, rather than the lines or areas themselves. This method, detailed in the following article, offers another avenue for enriching Power BI reports.

Conclusion

In sum, while Power BI may not inherently support dynamic color changes in line or area charts, creative solutions like overlaying charts with conditional visibility can effectively achieve this goal. Such techniques not only enhance the visual appeal of data representations but also add a layer of dynamic interactivity to reports. The ability to apply these methods across different scenarios, from data confidentiality to advanced charting techniques, underscores the versatility and power of custom solutions in Power BI.

You can download my report with all visuals and formatting as displayed in the cover picture of this article here.

Your feedback fuels my content! Engage through comments, and if you find value in such insights, your claps encourage more of this content. Thank you for your readership!

Stay Tuned

Make sure to follow me on Medium to access all my articles on advanced techniques in Power BI visualization.

Connect or Follow Me Here:

Don’t forget to subscribe to

👉 Power BI Publication

👉 Power BI Newsletter

and join our Power BI community

👉 Power BI Masterclass

Power Bi
Data Science
Data Visualization
Power Bi Tips And Tricks
Power Bi Tutorials
Recommended from ReadMedium