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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Sairokkam
Frequent Visitor

Highlight (apply color )Word in a sentence dynamically based on the input data

Hello experts,

 

I'm getting data like - I need <red>help<red>from you.

 

I need to show the output as - I need help from you.     

 

Here the word help should be in red color. Like this based on the input color given in the data PBI need to apply that color to the word automatically and delete <red>    <red> in the output. 

 

Any suggestions please.

Thanks in advance.

1 ACCEPTED SOLUTION
PhilipTreacy
Super User
Super User

Hi @Sairokkam 

 

Download example PBIX file

 

To expand further on this, if you have different words requiring different colors, e.g.

 

I need <red>help<red> from you, <green>please<green>

 

 

You can use Power Query to replace the <red> and <green> tags with the corresponsding HTML and CSS styles.  It just requires doing some Replace values steps, giving this

csshtml.png

 

So this defines CSS styles called red and green and applies these to the relevant words.

csshtml2.png

 

 

Regards

 

Phil

 

 



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


View solution in original post

7 REPLIES 7
PhilipTreacy
Super User
Super User

Hi @Sairokkam 

 

Download example PBIX file

 

To expand further on this, if you have different words requiring different colors, e.g.

 

I need <red>help<red> from you, <green>please<green>

 

 

You can use Power Query to replace the <red> and <green> tags with the corresponsding HTML and CSS styles.  It just requires doing some Replace values steps, giving this

csshtml.png

 

So this defines CSS styles called red and green and applies these to the relevant words.

csshtml2.png

 

 

Regards

 

Phil

 

 



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


Thanks a lot @PhilipTreacy 

PhilipTreacy
Super User
Super User

Hi @Sairokkam 

 

Download example PBIX file

 

I didn't quite get the question the first time, sorry.  Now I do - see the PBIX I linked to.

 

Using Power Query you can replace the <red><red> tags with the HTML/CSS you need to display the word using the HTML Content visual

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45W8lTIS01NUYgpNTAwTi5KTQEzUjNScwrQhBTSivJzFSrzS5ViYwE=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Message = _t]),
    #"Replaced Value" = Table.ReplaceValue(Source," <red>","<style> span {color:#ff0000;} </style><span> ",Replacer.ReplaceText,{"Message"}),
    #"Replaced Value2" = Table.ReplaceValue(#"Replaced Value","<red> ","</span> ",Replacer.ReplaceText,{"Message"})
in
    #"Replaced Value2"

 

Now you don't need any DAX, you can just add the text to the HTML visual and see the color correctly

htmlcol.png

 

Regards

 

Phil

 



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


PhilipTreacy
Super User
Super User

Hi @Sairokkam 

 

Download example PBIX file

 

If you use this visual HTML Content - Custom Visual for Power BI (html-content.com) you can do it.

 

After installing the visual, add one to the page.

 

I've set up a dummy measure

HTML Measure = 

VAR _Value = SELECTEDVALUE('DataTable'[Value])

VAR _Message = SELECTEDVALUE('DataTable'[Message])

VAR _StartText = "I need <style> span "

VAR _EndText = "</span> from you."

RETURN

IF ( _Value > 0, _StartText & "{color:#48e21a;} </style><span>" & _Message & _EndText, _StartText & "{color:#ff0000;} </style><span>" & _Message & _EndText )

 

 

 

to give this dependeing on the selected message

help1.pnghelp.png

 

Text color is controlled by the hex color code e.g. #ff00000.

 

I don't know how you are getting these messages or how you decide what color to use.  You'll need to modify your code to suit your needs.  Post back if you need help.

 

Regards

 

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


KerKol
Super User
Super User

You'll need to display the text in a HTML visual like this one:

Introduction: Shielded HTML Viewer - Power BI Visuals by Nova Silva

or this one:

HTML Content - Custom Visual for Power BI (html-content.com)

 

or remove the tags:

Convert Data From HTML To Plain Text In Power BI (c-sharpcorner.com)





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Hey thanks for your reply.

 

I'm able to remove tags using this.

https://www.c-sharpcorner.com/article/convert-data-from-html-to-plain-text-in-power-bi/

 

But the color menctioned in the tag needs to apply to the word automatically. Any suggestions.

Hmmm...

I don't recognise <red>help<red> so I'm afraid that suggestions I might give might take you down a rabbit hole...

Red is a valid CSS colour CSS Colors (w3schools.com) so you could potentially look at doing some find and search functions with power query and dax.





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.