web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / [Power Automate Deskto...
Power Automate
Unanswered

[Power Automate Desktop] Conditional formatting on cell value based colours in HTML table in email

(0) ShareShare
ReportReport
Posted on by 11

Hey guys.

 

I'm building a flow that extracts content from the SQL database, converts it to HTML and sends an email, but I want to change the cell color according to the situation. A simple IF would solve the problem, but I'm facing a syntax error.

 

%HTMLTable%
<tr>
<td style=\"border: 1px solid black; background-color: #f2f2f2; text-align: center;\">%CurrentItem[0]%</td>
<td style=\"border: 1px solid black; background-color: #f2f2f2; text-align: center;\">%CurrentItem[1]%</td>
<td style=\"border: 1px solid black; background-color: #f2f2f2; text-align: center;\">%CurrentItem[2]%</td>

<td style=\"border: 1px solid black; text-align: center; %IF(CurrentItem[3] > 4, 'background-color: #ff0000;', '')%\">%CurrentItem[3] %</td>

 

In this example, I want to insert a condition into CurrentItem[3].
If (CurrentItem[3] > 4, background-color = 'red', nothing), like this.

 

Categories:
I have the same question (0)
  • Verified answer
    Deenuji_Loganathan_ Profile Picture
    6,250 Super User 2025 Season 2 on at

    Hi @Douglas2,

     

    Please find the below proposed follow with another example:

     

    You cannot include if condition inside the variable instead follow the below approach.

    Considering the current item 3, we modified the color while appending the table row.

    Deenuji_0-1715787481518.png

     

     

    code:

     

    # Fetch Queryresult from SQL and if query not returns 0 rows then write HTML table for results and embedded that table in outlook message
    IF QueryResultCount > 0 THEN
     SET HTMLTable TO $'''<table style=\"border: 1px solid black;\">
    <tr>
    <th style=\"border: 1px solid black; padding: 8px; text-align: left; background-color: hashtag#f2f2f2;\">SL No</th>
    <th style=\"border: 1px solid black; background-color: hashtag#f2f2f2;\">Application</th>
    <th style=\"border: 1px solid black; background-color: hashtag#f2f2f2;\">Login</th>
    <th style=\"border: 1px solid black; background-color: hashtag#f2f2f2;\">STATUS</th>
    <th style=\"border: 1px solid black; background-color: hashtag#f2f2f2;\">ERROR</th>
    </tr>
    <tr>
    
    
    '''
     LOOP FOREACH CurrentItem IN ExcelData
     SET HTMLTable TO $'''%HTMLTable%
    <tr>
    <td style=\"border: 1px solid black; background-color: hashtag#f2f2f2;\">%CurrentItem[0]%</td>
    <td style=\"border: 1px solid black; background-color: hashtag#f2f2f2;\">%CurrentItem[1]%</td>
    <td style=\"border: 1px solid black; background-color: hashtag#f2f2f2;\">%CurrentItem[2]%</td>
    '''
     IF CurrentItem[3] = $'''UP''' THEN
     SET HTMLTable TO $'''%HTMLTable%
    <td style=\"border: 1px solid black; background-color: #008000;\">%CurrentItem[3]%</td>
    <td style=\"border: 1px solid black; background-color: hashtag#f2f2f2;\">%CurrentItem[4]%</td>
    </tr>
    '''
     ELSE
     SET HTMLTable TO $'''%HTMLTable%
    <td style=\"border: 1px solid black; background-color:hashtag#FF0000;\">%CurrentItem[3]%</td>
    <td style=\"border: 1px solid black; background-color: hashtag#f2f2f2;\">%CurrentItem[4]%</td>
    </tr>
    '''
     END
     END
     SET HTMLTable TO $'''%HTMLTable%
    </table>'''
     Outlook.SendEmailThroughOutlook.SendEmail Instance: OutlookInstance Account: $'''deenu@microsoft.com''' SendTo: $'''deenu@microsoft.com''' Subject: $'''Fruits stock details''' Body: $'''Hello, Hope your are doing good.
    
    Application current status details:
    %HTMLTable%''' IsBodyHtml: True IsDraft: False
    ELSE
     # Fetch Queryresult from SQL and if query returns 0 rows then send email without table
     Outlook.SendEmailThroughOutlook.SendEmail Instance: OutlookInstance Account: $'''xyz@gmail.com''' SendTo: $'''xyz@gmail.com''' Subject: $'''Fruits stocks ''' Body: $'''Hello, Hope your are doing good.
    
    Fruits stocks return null today''' IsBodyHtml: True

     

     

     

     

    Hope this helps!!

     


    Thanks,
    Deenuji Loganathan 👩‍💻
    Automation Evangelist 🤖
    Follow me on LinkedIn 👥

    -------------------------------------------------------------------------------------------------------------
    If I've helped solve your query, kindly mark my response as the solution ✔ and give it a thumbs up!👍 Your feedback supports future seekers 🚀

  • Douglas2 Profile Picture
    11 on at

    @Deenuji Thank you very much! You helped me a lot! I'm following you in Linkedin!

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 538 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 405 Moderator

#3
abm abm Profile Picture

abm abm 252 Most Valuable Professional

Last 30 days Overall leaderboard