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

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.

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.

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.

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…

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

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.

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.

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





