Ravindra BagaleCourses & study guides मराठी Track your progress

20. Dynamic Text and Dynamic Colour (Conditional Formatting)

20.8 KPI-based Colouring in Charts and Cards

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

  1. Create Promise Colour = IF([% Under 10] >= 0.5, "#107C10", "#D13438").
  2. City bar chart › Format › Visual › Bars › Colors › fx.
  3. Format style Field value › Based on field Promise Colour › OK.
  4. 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

  1. 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).
  2. Format visual › Visual › Bars › Colors › click fx next to Default color.
  3. Format style: Field value › [Delivery Time Colour] › OK. Stores slower than 15 minutes turn red.
  4. 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.

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.

Loading DAX practice tasks...

  1. Reject rate (Easy): Shown per Plant. Measure: Reject Rate = SUM of UnitsRejected ÷ SUM of UnitsMade.
  2. Units colour (Easy): Shown per Plant. Measure: Units Colour = green when [Units Made] is 2000 or more, else grey "#605E5C".
  3. Shift colour (Easy): Shown per Shift. Measure: Shift Colour = "#F2C811" for Day and "#252423" for Night.
  4. Reject colour (Medium): Shown per Plant. Measure: Reject Colour = red when the reject rate is above 0.02, else green.
  5. Three-colour rate (Medium): Shown per Part. Measure: Part Colour = red above 0.03, amber above 0.015, else green.
  6. Country colour (Medium): Shown per Country. Measure: Country Colour = "#FF9933" for India, else "#0078D4".
  7. Cost colour (Medium): Shown per Part. Measure: Cost Colour = red when AVERAGE of CostPerUnit is above 30, else green.
  8. Tick or cross (Hard): Shown per Part. Measure: Rate Icon = "✔" when the reject rate is 0.02 or less, else "✖".
  9. 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.
  10. Clean batches (Hard): Shown per Plant. Measure: Clean Batches = number of batches with UnitsRejected = 0.

Ravi Sir's Cards for this lesson

मराठी cards