Let's POWER Automate

From no-code to low-code

Menu
  • Expressions
  • Filters
  • General
  • Application specific solutions
    • Dataverse
    • Excel
    • Forms
    • Planner
    • Outlook
    • SharePoint
    • Teams
  • Triggers
  • Resources
  • ABOUT ME
  • Get help with your flow
Menu

Add multiple colours to your HTML table in Power Automate

Posted on May 31, 2023May 31, 2023 by Tom

“I’d like to use more than one colour in the HTML table, what would the Power Automate expression look like to add multiple colours?”


In the previous article I explained how to change colour in a table based on a value and send it in an email. But that article explained only how to add a single colour – the text was either black or red. What if that’s not enough? What if there should be more colours, e.g. red, orange, and green? How do you extend the expression while creating the HTML table?

Combine multiple if(…) expressions

The use case in the previous article was to show a date in red if it’s more than three days in the past. Using the if(…) expression it looked as below.

if(Date < Today - 3, <dateInRed>, <dateInBlack>)

Now let’s change it a bit and expand it. If the date is less than 3 days in the future, let’s make it red. If the date is less than 10 days in the future, it should be orange. For more than 10 days it should be green.

Translated to separate expression:

if(Date < Today + 3, <dateInRed>, <otherColour>)
if(Date < Today + 10, <dateInOrange>, <otherColour>)
if(Date >= Today + 10, <dateInGreen>, <otherColour>)

As described in a previous article, the combination should always start from the most strict condition. The Date more than 10 days in the future is safe, there’s no overlap with the others. Where you must be careful are the other two conditions – less than 3 days and less than 10 days. It’s because less than 3 is also less than 10, and if you do the conditions in a wrong order it’ll use the orange colour for all.

With that in mind, let’s start with the combination. Less than 3 must be first:

if(Date < Today + 3, <dateInRed>, <otherColour>)

If it’s not less than 3, let’s check if it’s less than 10.

if(Date < Today + 3, <dateInRed>, 
   if(Date < Today + 10, <dateInOrange>, <otherColour>)
)

Since there’s only one option left – the green colour – you can skip the third if(…) and just say that everything else will be green.

if(Date < Today + 3, <dateInRed>, 
   if(Date < Today + 10, <dateInOrange>, <dateInGreen>)
)

Use the dynamic contents to build the expression

That was the theoretical part, now you have to replace all the parts with the dynamic contents or expressions. Reusing the expressions from the original article.

if(less(item()?['Date'],addDays(utcNow(),3)), 
   concat('<span style="color:red">', item()?['Date'], '</span>'), 
   if(less(item()?['Date'],addDays(utcNow(),10)), 
      concat('<span style="color:orange">', item()?['Date'], '</span>'), 
      concat('<span style="color:green">', item()?['Date'], '</span>')
   )
)

Note: my column has internal name Date, yours might be different!

The last part is to take care of the HTML tags when sending the table in an email.

replace(replace(replace(body('Create_HTML_table'),'&lt;','<'),'&gt;','>'),'&quot;','"')

And that’s it, you’ll get a table with various colours depending on the values.

Power Automate table multiple colours

Summary

All you need to do to add multiple colours in a table created by Power Automate is to extend the if(…) expression. Start from the most limiting one, and keep adding them to the ifFalse part until you reach “the rest”. Replace the replaced html tags back when sending the email and you’ll get a colourful table.


Do you struggle with the various expressions, conditions, filters, or HTTP requests available in Power Automate?

I send one email per week with a summary of the new solutions, designed to help even non IT people to automate some of their repetitive tasks.

All subscribers have also access to resources like a SharePoint Filter Query cheat sheet or Date expressions cheat sheet.

Zero spam, unsubscribe anytime.

3 thoughts on “Add multiple colours to your HTML table in Power Automate”

  1. Phil says:
    June 2, 2023 at 3:57 pm

    Great job, got some use cases for that!
    I’d also love to see different text/background colors for specific headers.
    Looking forward to more!

    Reply
  2. Lan says:
    September 15, 2023 at 11:51 am

    I have problem with my IF statement. I want to check if the results of items Column1 is 1 or not. And mark it if it’s green or yellow.
    Its display to the screen all my IF statement, only the “background-color” is work.
    Here is my code:
    if(
    equals(item()?[‘Column1’], 1),
    concat(”, “✓”, ”),
    concat(”, “✕”, ”)
    )

    Reply
    1. Tom says:
      September 30, 2023 at 10:33 pm

      Hello Lan,
      Power Automate uses single quotes ‘text’ to define texts, not double quotes “text”.

      Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Do you know what to do, but not how to do it?

Get The Ultimate Power Automate expressions cheat sheet and translate your thoughts into flows with ease!


There's also the HTTP requests to SharePoint cheat sheet to help you overcome limitations of some standard actions!

Do you struggle with the various expressions, conditions, filters, or HTTP requests available in Power Automate?

I send one email per week with a summary of the new solutions, designed to help even non IT people to automate some of their repetitive tasks.

All subscribers have also access to resources like a SharePoint Filter Query cheat sheet or Date expressions cheat sheet.

Zero spam, unsubscribe anytime.

Didn't find what you were looking for?
Need to adjust a solution to fit your needs?
Or would you just like to get an assistance from somebody with 1000s of hours of experience with Power Automate?

Power Automate blogs worth visiting

Damien Bird
Dennis (Expiscornovus)
Paul Murana

©2023 Let's POWER Automate | Theme by SuperbThemes