20. Dynamic Text and Dynamic Colour (Conditional Formatting)
20.8 KPI-based Colouring in Charts and Cards
Quick answer: the short, self-contained version of this lesson is the guide Power BI Conditional Formatting.
Start with a problem
Rani wants the City bar chart coloured by the delivery promise: green when ≥ 50% under 10 minutes, red otherwise – on bars that show sales.
Explain simply
Use a colour measure that returns a hex code, then apply it with fx › Field value to the bars. The colour can depend on a different measure from the bar length.
Show the data
| City | Total Sales (₹) | % under 10 | Colour |
|---|---|---|---|
| Pune | 850 | 33.3% | Red |
| Nashik | 800 | 33.3% | Red |
| Kolhapur | 450 | 100.0% | Green |
About this data: This table uses columns: City, Total Sales (₹), % under 10, Colour. This table uses columns: City, Bar length, Bar colour. This table uses columns: Wrong result, Reason, Correction. Values shown are the lesson examples already on this page (not a new dataset).
Fictional sample data. Practice file: visuals_orders_apr_may_2026.csv (source: src/practice/).
Demonstrate
- Create
Promise Colour = IF([% Under 10] >= 0.5, "#107C10", "#D13438"). - City bar chart › Format › Visual › Bars › Colors › fx.
- Format style Field value › Based on field
Promise Colour› OK. - Add a text note: Colour = 10-minute promise, length = sales.
Show the result
Your result should look like this (fictional sample):
| City | Bar length | Bar colour |
|---|---|---|
| Pune | 850 | Red |
| Nashik | 800 | Red |
| Kolhapur | 450 | Green |
Explain what happened
For each bar, Power BI evaluates Promise Colour in that city's filter context and paints the bar with the returned hex code.
Explore further
- Use a target measure instead of 0.5 so the rule changes in one place.
Detailed reference for this lesson:
Bar chart with red bars for slow stores:
Steps in Power BI
- Bar chart: Y-axis = Store Name, X-axis = Avg Delivery Time (mins). There must be no field in Legend (conditional colour is not available with a legend).
- Format visual › Visual › Bars › Colors › click fx next to Default color.
- Format style: Field value ›
[Delivery Time Colour]› OK. Stores slower than 15 minutes turn red. - Analytics › Constant line at 15, labelled "15-min limit".
Other places for fx colours: card Callout value › Color (red Cancellation Rate above a threshold), General › Effects › Background (tint the whole card), Title font colour, line chart Markers, KPI visual colours, button fill, shape fill.
Cancellation Colour = IF([Cancellation Rate] > 0.05, "#D13438", "#107C10") -- 5% is a practice threshold
Platform Colour = SWITCH(SELECTEDVALUE(Orders[Platform]), "Blinkit", "#F2C811", "Amazon Now", "#232F3E", "#8A8886")
Accessibility
Some viewers have colour-vision deficiency, so do not rely on red/green alone. Add icons, labels or patterns, and check the contrast of text on coloured backgrounds (Module 23).
Practice task
(1) Create a dynamic title for the Delivery page showing selected cities and platform. (2) Colour a store bar chart with the delivery colour measure. (3) Add data bars to Total Orders and traffic-light icons to Cancellation Rate in a table. (4) Build a narrative card with Total Orders, Avg Delivery Time and % Under 10 Mins.
Ravindra Bagale's Tip
Friends, many students hard-code thresholds (for example 10 minutes) in several colour measures, then forget to change one of them. Put the target in a single measure or a small targets table, and reference it in every colour rule. Remember this rule.
Ravindra Bagale's Tip – मराठी
मित्रांनो, बरेच students अनेक colour measures मध्ये thresholds hard-code करतात (उदाहरणार्थ 10 minutes), आणि मग त्यातला एखादा बदलायला विसरतात. Target एकाच measure मध्ये किंवा छोट्या targets table मध्ये ठेवा, आणि प्रत्येक colour rule मध्ये त्याचाच संदर्भ द्या. हा नियम लक्षात ठेवा.
Ravindra Bagale's Tip – हिंदी
दोस्तों, बहुत से students कई colour measures में thresholds hard-code कर देते हैं (जैसे 10 minutes), फिर उनमें से किसी एक को बदलना भूल जाते हैं. Target को एक ही measure या छोटी targets table में रखो, और हर colour rule में उसी को refer करो. यह नियम याद रखो.
Fix common mistakes
| Wrong result | Reason | Correction |
|---|---|---|
| All bars one colour | Legend field present (fx disabled) | Remove the legend |
| Colour measure returns text like Red | Accepted names vary | Return hex codes |
| Readers confuse colour with sales | No explanation | Add a short note or legend text |
Practise independently
Practice task
If Pune's % under 10 rose to 66.7%, what colour would Pune be?
Hints
- ≥ 0.5 is green.
Solution
Green.
Think like a professional
Encoding a second measure in colour is powerful but must be explained on the page. Interviewers like hearing that you add the note.
Thodkyaat sangaycha tar (quick recap)
When you see the fx button, a measure can control that setting. Test titles for zero, one and many selections, and check the colour direction (is low good?). Now let us move on to dynamic charts.
fx button दिसला की ते setting measure ने control करता येतं; zero, एक आणि अनेक selections साठी title test करा; आणि colour ची direction (low is good का?) check करा. आता पुढे जाऊया dynamic charts कडे.
fx button दिखा तो वह setting measure से control की जा सकती है; zero, एक और कई selections के लिए title test कीजिए; और colour की direction (low is good है क्या?) check कीजिए. अब आगे बढ़ते हैं dynamic charts की ओर.
Loading DAX practice tasks...
- Reject rate (Easy): Shown per Plant. Measure: Reject Rate = SUM of UnitsRejected ÷ SUM of UnitsMade.
- Units colour (Easy): Shown per Plant. Measure: Units Colour = green when [Units Made] is 2000 or more, else grey "#605E5C".
- Shift colour (Easy): Shown per Shift. Measure: Shift Colour = "#F2C811" for Day and "#252423" for Night.
- Reject colour (Medium): Shown per Plant. Measure: Reject Colour = red when the reject rate is above 0.02, else green.
- Three-colour rate (Medium): Shown per Part. Measure: Part Colour = red above 0.03, amber above 0.015, else green.
- Country colour (Medium): Shown per Country. Measure: Country Colour = "#FF9933" for India, else "#0078D4".
- Cost colour (Medium): Shown per Part. Measure: Cost Colour = red when AVERAGE of CostPerUnit is above 30, else green.
- Tick or cross (Hard): Shown per Part. Measure: Rate Icon = "✔" when the reject rate is 0.02 or less, else "✖".
- Share target colour (Hard): Shown per Plant. Measure: Share Colour = green when [Units Made] is at least 0.25 × units of all plants, else red.
- Clean batches (Hard): Shown per Plant. Measure: Clean Batches = number of batches with UnitsRejected = 0.
Revision card
Interview card