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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Conditional formating ...
Power Automate
Unanswered

Conditional formating in 'Send an email (V2)

(0) ShareShare
ReportReport
Posted on by 2

Hello, 

 

I'm sorry if the answer has been listed somewhere, I really did try to look for it and couldn't find anything.

 

I have created a flow for quality checks where when I get a response from a Microsoft form, the responses go to a table in excel, in excel I've set up a formula to calculate a total result of the responses and all that data is then sent to the person who the quality check was done for.\

MantasV_0-1699529891289.png

What I need help with is, with conditional formatting for different types of responses, so first one would be the final result of it I want to be colored red if it's under 75, yellow if it's between 75 and 90 and green if it's above 90. I tried googling different codes to enter, but the result font seems to constantly turn out black regardless of what I do. 

And then kind of on the same page, I want to add conditions that if responses positive they would appear at one part of the e-mail and if responses were negative, they would appear at a different part of the e-mail. 

The e-mail is currently looking something like this:

MantasV_1-1699530389437.png

 

 

Any help would be greatly appreciated as I'm a little concerned that trying to enter codes into the e-mail is potentially a wrong approach all together. 

Categories:
  • annetoal Profile Picture
    1,934 Moderator on at

    Here's some conditional HTML formatting:

    First, create a variable to contain the result value. For illustration purposes, I have it in an Initialize variable action. I've named it MyNumber but you can name it whatever you want. Make the variable type Integer (unless there's a chance the value will ever have decimal points, in which case call it a Float. You will notice I have manually plugged in the value of 95 but this value should come from your code.

    annetoal_0-1699548361536.png

    Close-up:

    annetoal_1-1699548717269.png

    The next step is for purposes of illustration, to show you how to make a HTML string from the value. I am using an Initialize variable action to set value of a string called HTML.

    Then, use this expression to generate the HTML you can insert into the Send an Email (v2) action.

     

    if(less(variables('MyNumber'), 75),
     concat('<span style="color: red;">', string(variables('MyNumber')), '</span>'),
     if(and(greater(variables('MyNumber'), 75), lessOrEquals(variables('MyNumber'), 90)),
     concat('<span style="color: yellow;">', string(variables('MyNumber')), '</span>'),
     concat('<span style="color: green;">', string(variables('MyNumber')), '</span>')
     )
    )

     

    Now you can take the output of the HTML string variable and insert it into your HTML email:

    annetoal_2-1699548825492.png

    In this example, it sent an email consisting of a green number 95.

     

    Hope this helps,

    Anne

     

  • Anchov Profile Picture
    1,986 on at

    You can construct Power Automate expressions for color formatting using HTML. Here are some steps you can follow, though you'll need to modify them to suit your specific situation:

    1. I created a new manual flow that accepts a number:

    Anchov_0-1699548891751.png

    2. I create a compose Statement, that generates html according to your color formatting criteria:

    Anchov_1-1699548941564.png

    The expression I used to generate the correct color based on the number is:

     

    concat('<span style="color:', if(less(triggerBody()?['number'], 75), 'red', if(lessOrEquals(triggerBody()?['number'] , 90), 'yellow', 'green')), ';">', string(triggerBody()?['number']), '</span>')

     

    3. I send and email with the results:

    Anchov_2-1699549015529.png

    Email is generated showing the color formatted value:

    Anchov_3-1699549115247.png

     

    The same concept can be applied for formatting your email for positive or negative. 


    If I have answered your question, please mark your post as Solved.
    If you like my response, please give it a Thumbs Up.

    Cheers!
    Rick Hurt

  • MantasV Profile Picture
    2 on at

    Thank you both for your replies, I tried doing both of the methods, but I imagine I'm doing something wrong as it still doesn't work. 

    First the method with the 'Compose' function, I left the triggers and information as they were (maybe the trigger needs to be changed somehow? But I still need to get the information from the form, before the e-mail is composed) 

    MantasV_0-1699948858727.png

    But the resulting e-mail I get is this:

    concat('', string(triggerBody()?[100]), '')

     

     

    For the other method with the variables, I've entered it as advised just the first variable I used 'Float' since as you mentioned if the result may have decimal points, I should use that. 

    MantasV_2-1699949242747.png

    MantasV_3-1699949258379.png

    But in this case the flow wouldn't run and return results like this:

    The variable 'MyNumber' of type 'Float' cannot be initialized or updated with value of type 'String'. The variable 'MyNumber' only supports values of types 'Float, Integer'.

    MantasV_1-1699949148427.png

    I don't really understand this error as it seems to say it supports the type 'Float' but then that it can't be converted to string? 

     

     

    Again thank you both for your help and any further assistance would be greatly appreciated. 

  • Anchov Profile Picture
    1,986 on at

    Hi @MantasV ,

    The issue seems to be related to the expressions not being entered as formulas in the dynamic formula editor. Currently, they are being interpreted as plain text. Expressions enable you to add conditional logic to your actions and need to be processed by the Power Automate engine.

    If you are new to expressions, I recommend watching this tutorial: Power Automate Expressions Tutorial.

     

    But a short how-to:

    To do this, you need to enter them into the dynamic formula editor by:
    1. Click within the compose action, then click on the "Fx" button:

    Anchov_1-1699969434975.png

    2. Ensure you are in the "Expression" tab, and input your formula. Note that only expressions can be added here.

    Anchov_2-1699969563009.png

    3. If you need to add dynamic values (e.g., variables, outputs from other actions, etc.), use the dynamic values button.

    Anchov_3-1699969756058.png

    4. Click "Save" to insert the expression. It's crucial to note that the syntax must be precisely correct for the expression to save.

    5. Verify that the expression was entered correctly and placed where you intended it within the Compose action . Expressions are denoted by the "Fx" box. The rest of the text in the Compose will be interpreted as static HTML (in this case).

    Anchov_4-1699969904139.png
    Please Note: You could format the HTML directly in the email action (in the body). However, I recommend using a compose action (variables work too) because the email action tends to attempt to "fix" the HTML by adding unnecessary characters, potentially disrupting your carefully formatted HTML. Make sure your HTML is accurate in the compose statement.



     

     

     

  • annetoal Profile Picture
    1,934 Moderator on at

    You need to turn the variable MyNumber into a string. Use this expression in place of where you have MyNumber in the email:

    string(variables('MyNumber')

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Automate

#1
Mohsin Ali Profile Picture

Mohsin Ali 414

#2
11manish Profile Picture

11manish 331 Super User 2026 Season 2

#3
M Bilal Khan Profile Picture

M Bilal Khan 274

Last 30 days Overall leaderboard