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 / Flow with multiple con...
Power Automate
Unanswered

Flow with multiple conditions to send an email

(0) ShareShare
ReportReport
Posted on by 68

I have a flow that is pulling data from Power Bi via a query then creating a HTML table to send an email.  However, I have a condition to check if the HTML table is empty so an email will not be triggered.  I need a second condition to to check a field, "Action" for a specific value (no action, supervisor, and manager) to trigger the email base on that value.  Example, no action it goes to one address, supervisor goes to another address, and manager goes to another email address.  I thought I could use a switch but I don't know the expression to use to filter by the field, "Action" to add the switch.

 

I am very new to creating flows and this one has me stumped.  

2023-09-19 08_41_18-Window.png

 

2023-09-19 08_42_28-Window.png

 

Categories:
I have the same question (0)
  • creativeopinion Profile Picture
    10,502 Super User 2025 Season 2 on at

    @KONeill102399 The Select action returns an array of items. You should use the length() function to check how many items are returned. If there are no results, a zero would be returned. How many items are returned in the Select action—if there is more than one item, the switch action may not work in this case (at least not from where it is currently placed in your flow).

     

    Can you show the output of the HTML table? 

     

  • KONeill102399 Profile Picture
    68 on at

    There is one column, "Action" that needs to be checked but return (3) different paths.  Here is the output from the HTML table.  I want to check the column, "Action" to escalate the issue base on the value.2023-09-19 09_21_29-WMI PGI Failure Report - 09_19_2023 - Message (HTML).png

  • creativeopinion Profile Picture
    10,502 Super User 2025 Season 2 on at

    @KONeill102399 The logic of your flow might need to be adjusted. Currently you are creating the HTML table first then running the check. 

     

    Is the intention to send the entire HTML table to a specific email address or only to send a specific row of data to a specific address?

  • KONeill102399 Profile Picture
    68 on at

    I want to send the entire HTML table in the email not the specific rows with the data.  

  • creativeopinion Profile Picture
    10,502 Super User 2025 Season 2 on at

    @KONeill102399 I'm still a bit unclear on how you plan to evaluate the Action column. In the screenshot you sent there are 4 rows of data. Is it assumed that each row has the same action in this case? Or could each row have different actions? Could you clarify?

     

  • eliotcole Profile Picture
    4,363 Moderator on at

    Hi, @KONeill102399 , couple of things that I think that you might need:

    1. Make A 'uniqueActionsArrVAR' Array Variable - I am pretty sure that you'll need to build an array of values from that 'Actions' column, then run an apply to each on a union() of that array
    2. Remove 'Format Table Headers' Action - I'm making an assumption here, but the 'Select Data from Query' action is going to enable you to set your headers, then you can use the 'Create HTML Table' on auto afterwards. (or just go straight to the table!)

    The need for the first is because you cannot be sure that all the actions will be the same, so your Switch action would not be run appropriately, as it would not have direct data to feed off of. Once you are inside that unique array, though, you can just place 'Current item' in the Switch 'On' field.

     

    I think this is why @creativeopinion was wondering why there wasn't any flow actions around handling those Actions from from BI data.

     

    How To Iterate Over The Actions

    All of this is hopefully not too strenuous to achieve ... I have edited in here some steps to ensure that you are not making 3 email actions:

    1. Initialize two new variables before all your other actions:
      1. Array - Named 'uniqueActionsArrVAR'
      2. String - Named 'emailRecipientsVAR'
         
    2. After the Power BI action make a separate Select action (don't delete your current one) and rename it 'Select uniqueActions'
      • In the 'From' field use the same value as you did in the other
      • In the 'Map' field you might need to get a bit creative, but hopefully you can just select the column

        That will result in a string array, that should look something like the example below these steps
         
    3. After the Select action create a Set variable action to set the 'uniqueActionsArrVAR' value then within that:
      1. ... in the 'Value' field of this action open the expression builder instead of using dynamic data
      2. ... add the union() function
      3. ... inside the union function add the output of 'Select uniqueActions' twice, comma separated

        Each time this runs you will now have a definable list of whether any actions are needed
         
    4. Now add an Apply to each action after all the other important actions in the flow (the ones you've shown us):
      1. In the 'Select an output from previous steps' field of the Apply to each select 'uniqueActionsArrVAR' from the Dynamic data
      2. As the first step create a Switch action and in the 'On' field select 'Current item' from the Dynamic data and make your 3 cases:
        1. supervisor
        2. manager
        3. no action
      3. After the switch add your email action and in the 'To' field pick the 'emailRecipientsVAR' from the Dynamic data and fill out the email with all the data

     

    Select Output Examples

    The output from the Select Action in #3 might look like this:

    [
     "supervisor",
     "manager",
     "no action"
    ]

     

    Or it might look like this:

    [
     "supervisor",
     "no action"
    ]

    It will all depend on what actions are listed in the BI data.

     

    Moving Forward

    Now you have your Switch and it will run on whichever values you choose in the cases, with whichever actions that you wish to have taken within them for each!

     

    Additionally, if you wanted to be super clever, much of this could be done in parrallel to your other actions, then run your Apply to each action after everything. This would assist with making the flow more efficient. 🙂

     

    If you wished to personalise the body of the email for supervisor/manager/no action, then either move the email action back into the Switch, or make an email body variable to edit there.

     

    When making new actions it's good to get into the habit of giving them unique names, too. To make it easy for myself on things like initializing variables I simply copy the variable name and paste it in instead of the word 'variable' in the renaming.

  • KONeill102399 Profile Picture
    68 on at

    Each row might have a different action but I want the entire table to be sent each time.

  • eliotcole Profile Picture
    4,363 Moderator on at

    Yes, it will. 🙂

     

    (apologies, assumed that was responding to me, just seen the reply part)

     

    So, with what I'm suggesting, let's say that example array is the output of the union() that I spoke of.

     

    Well, the output from the Select I suggested might have been:

     

    [
     "supervisor",
     "no action",
     "no action",
     "manager",
     "no action",
     "manager",
     "manager",
     "no action"
    ]

     

    The union() will remove all the duplicates. So it will only send as many emails as there are different types of actions. However you would still use the output from your original create html table in the emails that you send. 🙂

     

    If you wanted to be even cleverer with the Switch, then you could have a single email action after it inside the apply to each, then in the switch just update an emailRecipientsVAR string variable and place that in your email 'To' field!

     

    (imma update my steps with that, I think ... and make the array more contextually apt)

  • KONeill102399 Profile Picture
    68 on at

    Wow!  That is a lot of information.  I will have to try this later today.  I did convert the data to an array, filter by the column, and created an apply to each to read the data.  But I wasn't sure where this should have happen in conjunction with the condition and formatting the table.  The, Format Table Headers' Action is so I can add spaces in the headers so it is easier to read for the user.  

     

    I am really new to power automate so this is extremely helpful.  I will try this.  

  • eliotcole Profile Picture
    4,363 Moderator on at

    No wuckas, @KONeill102399 ... take your time ... and most of all ... try some sh ... stuff out!

     

    If you want to protect yourself you can always place strategic 'Terminate' actions, and or use fake data. Or, in your case use your own email address for each Switch case.

     

    Oh, and sorry for the wall of text.

     

    Times gone by I would map it all out for you with a flow and suchlike, but I'm literally working on this stuff now, so it's hard to push around all that ... resource-wise. 🙂

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 525 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 324 Moderator

#3
abm abm Profile Picture

abm abm 232 Most Valuable Professional

Last 30 days Overall leaderboard