Expression for Report Builder to Highlight/Format Specific Word

Tamayo, Ashley 121 Reputation points
2022-11-22T13:13:12.683+00:00

I'm struggling to find a way to highlight specific text in a cell. I have a report that searches for a specific word and I'd like to further highlight where that word is in the results. Is there an expression I can use to turn just one word a different color but leave everything else normal? For example in the sentence "Sally went to the store and bought 5 different shifts", I would like to only highlight/format "store" and leave the rest of the sentence normal.

I tried to use =iff(fields!text.value like 'store', "red","Black") but encountered an error.

The number of characters that are used and the position of the word that appears, will change on each row of the results.

I'm also ok with the option to do this in Excel if possible. I tried different highlight rules, but none of them are returning the results I need.

Thank you!

SQL Server Reporting Services
SQL Server Reporting Services
A SQL Server technology that supports the creation, management, and delivery of both traditional, paper-oriented reports and interactive, web-based reports.
2,815 questions
Excel Management
Excel Management
Excel: A family of Microsoft spreadsheet software with tools for analyzing, charting, and communicating data.Management: The act or process of organizing, handling, directing or controlling something.
1,649 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Michael Taylor 48,976 Reputation points
    2022-11-22T15:55:10.017+00:00

    Changing the formatting of text in the middle of an expression isn't trivial. SSRS supports it in later versions but it really isn't designed for what you're doing. It is designed for putting data within a larger, fixed label. This can be done using a placeholder. But given your goal I'm not sure how you could do that correctly.

    One approach that might work is to break up your actual expression into 3 separate expressions. I cannot imagine the performance is going to be good but it might work. You would have a "before", "actual" and "after" expression. Of course this ideally would need to be done in the query and not the rendering. You could then format the "actual" expression with highlighting. But of course this would break down if you had it appear multiple times.

    The linked article also mentions using HTML tags around the block of text. This might be the easiest approach as you could use string replacement to accomplish it. However if you export to Excel/PDF then it might not render properly so ensure you test export if you need that functionality.

    0 comments No comments

  2. AniyaTang-MSFT 12,326 Reputation points Microsoft Vendor
    2022-11-23T02:18:00.663+00:00

    Hi @Tamayo, Ashley
    I think you can use Placeholder Properties and HTML Tags to achieve your requirement.
    I did a test.

    1.First double-click the text box to open the Placeholder Properties.
    263271-1.png

    2.Then select "HTML..." in the Markup Type option.
    263206-2.png

    3.Then we set the value and use the replace function to replace "store" with "store" in red.

    =REPLACE(Fields!Text.Value, "store","<font color='red'>store</font>")  
    

    263140-3.png

    Preview:
    263207-4.png

    Best regards,
    Aniya

    0 comments No comments