Skip to main content

Notifications

Community site session details

Community site session details

Session Id : GIpXE7bjLrXFi5L57TTHOh
Power Automate - Building Flows
Unanswered

Flow with multiple conditions to send an email

Like (0) ShareShare
ReportReport
Posted on 19 Sep 2023 13:48:39 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

 

  • eliotcole Profile Picture
    4,218 Super User 2025 Season 1 on 22 Sep 2023 at 12:19:31
    Re: Flow with multiple conditions to send an email

    Hey, @KONeill102399 , all you should need to change is to make this:

     

    not good.png

     

    Look like this:

    good.png

     Then you will have a string array. 🙂

    If you are wondering how to change the view, just tap the button on the side I've shown it with the tool tip, here:

    common - switch to text mode.png

     

  • creativeopinion Profile Picture
    10,406 Super User 2025 Season 1 on 21 Sep 2023 at 16:43:08
    Re: Flow with multiple conditions to send an email

    @KONeill102399 I believe I now have a better understanding of your requirements.

     

    In your particular case, the Switch action will not work. Reason being is that you are looking at the Action column values as a whole (not individual). For this reason you will need to extract those values and combine them together. 

     

    I don't actually use Power BI in my daily workflow. However, I was able to come up with a solution that I think will work.

    Count Data Returned from Power BI

    After the Run a query against a dataset action, add a Compose action. 

     

    Use the length() function to count the First table rows. You indicated in your original post that you wanted to check if the HTML table was empty. I think it would make more sense to check if there is any data returned (if not, then don't bother continuing on with the flow).

     

    creativeopinion_0-1695311977915.png

     

    Add Condition

    Add a Condition action. Insert the outputs from the Compose action above. If the length returned is not equal to 0 (this means there is data).

     

    Insert all your actions in the YES branch. 

    creativeopinion_1-1695311993976.png

     

    Here is where you can add your HTML table actions. 

     

    creativeopinion_9-1695312886707.png

     

    Select the Actions

    For my example, I'm using a column named Status. In the outputs of the Run a query against a dataset action the key for the Status column is "MyTable[Status]" which I'll use in the Select action.

     

    creativeopinion_4-1695312552560.png

    In the Select action, insert the First table rows dynamic content into the From field. Click on the icon to the right of the Map field to switch from Map to Key value mode. 

     

    creativeopinion_10-1695313193104.png

    Insert an expression into the Map field. You'll need to use the item() function, add a question mark, square brackets and single quotes (shown below).

    item()?['']

    In between the single quotes, enter the key of your column. The key is the red text between the double quotes. In my case, my key is: MyTable[Status]

    My expression is:

    item()?['MyTable[Status]']

    creativeopinion_3-1695312530221.png

     

    Run a test! Check the outputs of your select action. It should return ALL values from the Action column, in my case the Status column. Keep in mind, the output of the Select action is an array of values.

     

    creativeopinion_2-1695312516236.png

     

    Unique List

    This next step is optional. You can use the union() function to create a unique list of values (removing all duplicate values). 

     

    Insert an expression with the union() function. The union() function takes two arrays. You can insert the outputs from the select action.

    union([array 1], [array 2])

    creativeopinion_6-1695312653294.png

     

    Join List (array to string)

    Next, add a Join action to convert the array to a string. Insert the outputs from the Compose action above (with unique values) into the From field.

     

    In the Join with field, enter a comma (or semi-colon.. any separator) and a space. 

    creativeopinion_11-1695313691693.png

     

    Run a test. View the outputs. You can see the input is an array, the output is a string of text separated by a comma.

     

    creativeopinion_7-1695312736817.png

     

    Condition Check

    The reason that the Switch action will not work in your case is that you have multiple values you are looking at. Instead, you need to run a Condition check to see if the outputs contain the value(s) you are looking for. 

     

    Add a condition action. In the first value field insert the outputs from the Join action. Change the operator to contains. Since this is a string of text you are checking against, you want to check if it contains the value you'll be entering into the second value field.

     

    In the second value field, insert the text you'd like to search for. Keep in mind this text is case sensitive

    creativeopinion_8-1695312752507.png

     

    Send an Email

    Add a send an email action to the YES branch. Insert the appropriate recipients and content. 

    creativeopinion_16-1695314466417.png

     

    Repeat for Each Action Type

    For each Action type, you'll need to create a condition. You can run these parallel to each other since you've indicated that items may have different conditions. Either way you will need to send an email to specific recipients depending on the action type. 

    creativeopinion_17-1695314571313.png

     

     

    Hope this helps!


    If I helped you solve your problem—please mark my post as a solution ✅.
    Consider giving me a 👍 if you liked my response!

    👉 Watch my tutorials on YouTube
    👉 Tips and Tricks on TikTok

     

     

     

     

     

  • KONeill102399 Profile Picture
    68 on 21 Sep 2023 at 12:43:18
    Re: Flow with multiple conditions to send an email

    That is #3.  I thought that what I did was wrong too because the header of the array displayed in the output.  Here are my screen shots.

    2023-09-21 07_38_43-Edit your flow _ Power Automate.pngRun-History-Power-Automate.pngEdit-your-flow-Power-Automate.png

  • eliotcole Profile Picture
    4,218 Super User 2025 Season 1 on 21 Sep 2023 at 11:03:57
    Re: Flow with multiple conditions to send an email

    Can you maybe show a screenshot?

     

    I suspect it is in the Map section of the Select action.

     

    Make sure that you have ONLY the selected field in there. You may need to press the little 'T' button to the right to do this.

     

    It should look something like this:

    something like this.png

     

  • KONeill102399 Profile Picture
    68 on 20 Sep 2023 at 20:30:11
    Re: Flow with multiple conditions to send an email

    I got everything to work except the Apply to each.  I received this error message:

    The execution of template action 'Switch' failed: The result of the evaluation of 'scope' action expression '@items('Apply_to_each')' is not valid. It is of type 'Object' but is expected to be a value of type 'String, Integer'.

     

    I am not sure what this means.

     

  • eliotcole Profile Picture
    4,218 Super User 2025 Season 1 on 19 Sep 2023 at 17:41:21
    Re: Flow with multiple conditions to send an email

    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. 🙂

  • KONeill102399 Profile Picture
    68 on 19 Sep 2023 at 17:29:38
    Re: Flow with multiple conditions to send an email

    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,218 Super User 2025 Season 1 on 19 Sep 2023 at 17:17:50
    Re: Flow with multiple conditions to send an email

    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 19 Sep 2023 at 17:16:28
    Re: Flow with multiple conditions to send an email

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

  • eliotcole Profile Picture
    4,218 Super User 2025 Season 1 on 19 Sep 2023 at 17:03:49
    Re: Flow with multiple conditions to send an email

    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.

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

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,731 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 66,077 Most Valuable Professional

Leaderboard