Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Calling all Data Engineers! Fabric Data Engineer (Exam DP-700) live sessions are back! Starting October 16th. Sign up.

Reply
Sania-F
Resolver I
Resolver I

In a text box add 3 dynamic values, and change their font color based on given conditions.

I have a measure table with 3 measures-> sales, revenue %, profit %.
I want to show these measures dynamically in a single text box.

The requirement is if sales > 0 return font in green color, if sales <0 return font in red color, if sales between 0 to -500 show in amber color.
If revenue % is > or equal to 90% show font in green color, else show in red color.
if profit % <0 then red , if >0 then green font.
How can I write DAX for above requirement

My text box would be like -
example 1 - sales for xyz is -200, revenue% is 40% , profit % is  -20%  [when date slicer is selected for -April]
example 2 - sales for xyz is 500, revenue% is 90% , profit % is  40% [when date slicer is selected for -March]

basically the numbers inside text box are dynamic values which will change based on my selections in a date slicer.
Thankyou for your help in advance 🙂

1 ACCEPTED SOLUTION
Jaytam
Frequent Visitor

@Sania-F  Follow the following steps which I have already done in my use and its worked:

 

  • To achieve the requirement of dynamically displaying measures in a text box with conditional font coloring in Power BI, you will need to use DAX to create formatted strings and conditional formatting to apply the colors. Here’s how you can achieve this step-by-step:
  • Create the SalesText measure:
  • SalesText =
    VAR SalesValue = SELECTEDVALUE(SalesData[Sales])
    RETURN
    SWITCH(
    TRUE(),
    SalesValue > 0, "<span style='color:green'>" & FORMAT(SalesValue, "#,##0") & "</span>",
    SalesValue < -500, "<span style='color:red'>" & FORMAT(SalesValue, "#,##0") & "</span>",
    SalesValue >= -500 && SalesValue < 0, "<span style='color:orange'>" & FORMAT(SalesValue, "#,##0") & "</span>",
    "<span style='color:black'>" & FORMAT(SalesValue, "#,##0") & "</span>"
    )

 

  • Create the RevenuePctText measure:
  • RevenuePctText =
    VAR RevenuePctValue = SELECTEDVALUE(SalesData[Revenue %])
    RETURN
    IF(
    RevenuePctValue >= 0.9,
    "<span style='color:green'>" & FORMAT(RevenuePctValue, "0%") & "</span>",
    "<span style='color:red'>" & FORMAT(RevenuePctValue, "0%") & "</span>"
    )

 

  • Create the ProfitPctText measure:
  • ProfitPctText =
    VAR ProfitPctValue = SELECTEDVALUE(SalesData[Profit %])
    RETURN
    IF(
    ProfitPctValue > 0,
    "<span style='color:green'>" & FORMAT(ProfitPctValue, "0%") & "</span>",
    "<span style='color:red'>" & FORMAT(ProfitPctValue, "0%") & "</span>"
    )
  • Create the CombinedText measure:
  • CombinedText =
    "Sales for xyz is " & [SalesText] & ", revenue% is " & [RevenuePctText] & ", profit % is " & [ProfitPctText]
  • Add a Date Slicer:

    • Add a slicer visual to your report and drag the Date column to the slicer.

 

Display the Combined Text:

  • Download the "HTML Content" visual from the Power BI marketplace if it's not already installed.
  • Add the "HTML Content" visual to your report.
  • Configure the visual to use the CombinedText measure as its value.

This setup will demonstrate how the text dynamically updates with different font colors based on the conditions you specified.

 

If this works. Please marked as a solution done.😊

View solution in original post

2 REPLIES 2
Jaytam
Frequent Visitor

@Sania-F  Follow the following steps which I have already done in my use and its worked:

 

  • To achieve the requirement of dynamically displaying measures in a text box with conditional font coloring in Power BI, you will need to use DAX to create formatted strings and conditional formatting to apply the colors. Here’s how you can achieve this step-by-step:
  • Create the SalesText measure:
  • SalesText =
    VAR SalesValue = SELECTEDVALUE(SalesData[Sales])
    RETURN
    SWITCH(
    TRUE(),
    SalesValue > 0, "<span style='color:green'>" & FORMAT(SalesValue, "#,##0") & "</span>",
    SalesValue < -500, "<span style='color:red'>" & FORMAT(SalesValue, "#,##0") & "</span>",
    SalesValue >= -500 && SalesValue < 0, "<span style='color:orange'>" & FORMAT(SalesValue, "#,##0") & "</span>",
    "<span style='color:black'>" & FORMAT(SalesValue, "#,##0") & "</span>"
    )

 

  • Create the RevenuePctText measure:
  • RevenuePctText =
    VAR RevenuePctValue = SELECTEDVALUE(SalesData[Revenue %])
    RETURN
    IF(
    RevenuePctValue >= 0.9,
    "<span style='color:green'>" & FORMAT(RevenuePctValue, "0%") & "</span>",
    "<span style='color:red'>" & FORMAT(RevenuePctValue, "0%") & "</span>"
    )

 

  • Create the ProfitPctText measure:
  • ProfitPctText =
    VAR ProfitPctValue = SELECTEDVALUE(SalesData[Profit %])
    RETURN
    IF(
    ProfitPctValue > 0,
    "<span style='color:green'>" & FORMAT(ProfitPctValue, "0%") & "</span>",
    "<span style='color:red'>" & FORMAT(ProfitPctValue, "0%") & "</span>"
    )
  • Create the CombinedText measure:
  • CombinedText =
    "Sales for xyz is " & [SalesText] & ", revenue% is " & [RevenuePctText] & ", profit % is " & [ProfitPctText]
  • Add a Date Slicer:

    • Add a slicer visual to your report and drag the Date column to the slicer.

 

Display the Combined Text:

  • Download the "HTML Content" visual from the Power BI marketplace if it's not already installed.
  • Add the "HTML Content" visual to your report.
  • Configure the visual to use the CombinedText measure as its value.

This setup will demonstrate how the text dynamically updates with different font colors based on the conditions you specified.

 

If this works. Please marked as a solution done.😊

Anand24
Super User
Super User

@Sania-F ,
You can't conditionally format some words inside a Power BI text box. You will require grouping of 3 text boxes and 3 card visuals (one each for sales, revenue and profit) and manually adjustments so that they seem like a single text line.

 

You can then conditionally format the callout value of card visuals individually using Rules to achieve required color. You won't even require DAX for it.
Here is a snap to understand the conditional formatting:

Anand24_0-1717422240344.png

 



Helpful resources

Announcements
FabCon Global Hackathon Carousel

FabCon Global Hackathon

Join the Fabric FabCon Global Hackathon—running virtually through Nov 3. Open to all skill levels. $10,000 in prizes!

September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 2025 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors
Top Kudoed Authors