Showing results for 
Search instead for 
Did you mean: 
Helper I
Helper I

Flow with multiple conditions to send an email

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


Super User
Super User

@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? 


Helper I
Helper I

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

@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?

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

@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?


Super User
Super User

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:

  "no action"


Or it might look like this:

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

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

Super User
Super User

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:


  "no action",
  "no action",
  "no action",
  "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)

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.  

Super User
Super User

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

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.


Super User
Super User

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


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

Super User
Super User

@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).




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. 



Here is where you can add your HTML table actions. 




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.



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. 



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


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:




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.




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])



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. 



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.




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



Send an Email

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



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. 




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






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


not good.png


Look like this:


 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


Helpful resources


Update! June 13th, Community Ambassador Call for User Group Leaders and Super Users

Calling all Super Users & User Group Leaders   UPDATE:  We just wrapped up June's Community Ambassador monthly calls for Super Users and User Group Leaders. We had a fantastic call with lots of engagement. We are excited to share some highlights with you!    Big THANK YOU to our special guest Thomas Verhasselt, from the Copilot Studio Product Team for sharing how to use Power Platform Templates to achieve next generation growth.     A few key takeaways: Copilot Studio Cookbook Challenge:  Week 1 results are posted, Keep up the great work!Summer of Solutions:  Starting on Monday, June 17th. Just by providing solutions in the community, you can be entered to win tickets to Power Platform Community Conference.Super User Season 2: Coming SoonAll communities moving to the new platform end of July We also honored two different community members during the call, Mohamed Amine Mahmoudi and Markus Franz! We are thankful for both leaders' contributions and engagement with their respective communities. 🎉   Be sure to mark your calendars and register for the meeting on July 11th and stay up to date on all of the changes that are coming. Check out the Super User Forum boards for details.   We're excited to connect with you and continue building a stronger community together.   See you at the call!

Copilot Cookbook Challenge | Week 2 Results | Win Tickets to the Power Platform Conference

We are excited to announce the "The Copilot Cookbook Community Challenge is a great way to showcase your creativity and connect with others. Plus, you could win tickets to the Power Platform Community Conference in Las Vegas in September 2024 as an amazing bonus.   Two ways to enter: 1. Copilot Studio Cookbook Gallery: 2. Power Apps Copilot Cookbook Gallery:   There will be 5 chances to qualify for the final drawing: Early Bird Entries: March 1 - June 2Week 1: June 3 - June 9Week 2: June 10 - June 16Week 3: June 17 - June 23Week 4: June 24 - June 30     At the end of each week, we will draw 5 random names from every user who has posted a qualifying Copilot Studio template, sample or demo in the Copilot Studio Cookbook or a qualifying Power Apps Copilot sample or demo in the Power Apps Copilot Cookbook. Users who are not drawn in a given week will be added to the pool for the next week. Users can qualify more than once, but no more than once per week. Four winners will be drawn at random from the total qualifying entrants. If a winner declines, we will draw again at random for the next winner.  A user will only be able to win once. If they are drawn multiple times, another user will be drawn at random. Prizes:  One Pass to the Power Platform Conference in Las Vegas, Sep. 18-20, 2024 ($1800 value, does not include travel, lodging, or any other expenses) Winners are also eligible to do a 10-minute presentation of their demo or solution in a community solutions showcase at the event. To qualify for the drawing, templates, samples or demos must be related to Copilot Studio or a Copilot feature of Power Apps, Power Automate, or Power Pages, and must demonstrate or solve a complete unique and useful business or technical problem. Power Automate and Power Pagers posts should be added to the Power Apps Cookbook. Final determination of qualifying entries is at the sole discretion of Microsoft. Weekly updates and the Final random winners will be posted in the News & Announcements section in the communities on July 29th, 2024. Did you submit entries early?  Early Bird Entries March 1 - June 2:  If you posted something in the "early bird" time frame complete this form: if you would like to be entered in the challenge.   Week 1 Results:  Congratulations to the Week 1 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Copilot Cookbook Gallery:Power Apps Cookbook Gallery:1.  @Mathieu_Paris 1.   @SpongYe 2.  @Dhanush 2.   @Deenuji 3.  n/a3.   @Nived_Nambiar  4.  n/a4.   @ManishSolanki 5.  n/a5.    n/a   Week 2 Results:  Congratulations to the Week 2 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Copilot Cookbook Gallery:Power Apps Cookbook Gallery:1. Kasun_Pathirana1. ManishSolanki2. cloudatica2. madlad3. n/a3. SpongYe4. n/a4. n/a5. n/a5. n/a

Win free tickets to the Power Platform Conference | Summer of Solutions

We are excited to announce the Summer of Solutions Challenge!    This challenge is kicking off on Monday, June 17th and will run for (4) weeks.  The challenge is open to all Power Platform (Power Apps, Power Automate, Copilot Studio & Power Pages) community members. We invite you to participate in a quest to provide solutions to as many questions as you can. Answers can be provided in all the communities.    Entry Period: This Challenge will consist of four weekly Entry Periods as follows (each an “Entry Period”)   - 12:00 a.m. PT on June 17, 2024 – 11:59 p.m. PT on June 23, 2024 - 12:00 a.m. PT on June 24, 2024 – 11:59 p.m. PT on June 30, 2024 - 12:00 a.m. PT on July 1, 2024 – 11:59 p.m. PT on July 7, 2024 - 12:00 a.m. PT on July 8, 2024 – 11:59 p.m. PT on July 14, 2024   Entries will be eligible for the Entry Period in which they are received and will not carryover to subsequent weekly entry periods.  You must enter into each weekly Entry Period separately.   How to Enter: We invite you to participate in a quest to provide "Accepted Solutions" to as many questions as you can. Answers can be provided in all the communities. Users must provide a solution which can be an “Accepted Solution” in the Forums in all of the communities and there are no limits to the number of “Accepted Solutions” that a member can provide for entries in this challenge, but each entry must be substantially unique and different.    Winner Selection and Prizes: At the end of each week, we will list the top ten (10) Community users which will consist of: 5 Community Members & 5 Super Users and they will advance to the final drawing. We will post each week in the News & Announcements the top 10 Solution providers.  At the end of the challenge, we will add all of the top 10 weekly names and enter them into a random drawing.  Then we will randomly select ten (10) winners (5 Community Members & 5 Super Users) from among all eligible entrants received across all weekly Entry Periods to receive the prize listed below. If a winner declines, we will draw again at random for the next winner.  A user will only be able to win once overall. If they are drawn multiple times, another user will be drawn at random.  Individuals will be contacted before the announcement with the opportunity to claim or deny the prize.  Once all of the winners have been notified, we will post in the News & Announcements of each community with the list of winners.   Each winner will receive one (1) Pass to the Power Platform Conference in Las Vegas, Sep. 18-20, 2024 ($1800 value). NOTE: Prize is for conference attendance only and any other costs such as airfare, lodging, transportation, and food are the sole responsibility of the winner. Tickets are not transferable to any other party or to next year’s event.   ** PLEASE SEE THE ATTACHED RULES for this CHALLENGE**

Celebrating the June Super User of the Month: Markus Franz

Markus Franz is a phenomenal contributor to the Power Apps Community. Super Users like Markus inspire others through their example, encouragement, and active participation.    The Why: "I do this to help others achieve what they are trying to do. As a total beginner back then without IT background I know how overwhelming things can be, so I decided to jump in and help others. I also do this to keep progressing and learning myself." Thank you, Markus Franz, for your outstanding work! Keep inspiring others and making a difference in the community! 🎉  Keep up the fantastic work! 👏👏 Markus Franz | LinkedIn  Power Apps: mmbr1606  

Your Moment to Shine: 2024 PPCC’s Got Power Awards Show

For the third year, we invite you, our talented community members, to participate in the grand 2024 Power Platform Community Conference's Got Power Awards. This event is your opportunity to showcase solutions that make a significant business impact, highlight extensive use of Power Platform products, demonstrate good governance, or tell an inspirational story. Share your success stories, inspire your peers, and show off some hidden talents.  This is your time to shine and bring your creations into the spotlight!  Make your mark, inspire others and leave a lasting impression. Sign up today for a chance to showcase your solution and win the coveted 2024 PPCC’s Got Power Award. This year we have three categories for you to participate in: Technical Solution Demo, Storytelling, and Hidden Talent.      The Technical solution demo category showcases your applications, automated workflows, copilot agentic experiences, web pages, AI capabilities, dashboards, and/or more. We want to see your most impactful Power Platform solutions!  The Storytelling category is where you can share your inspiring story, and the Hidden Talent category is where your talents (such as singing, dancing, jump roping, etc.) can shine! Submission Details:  Fill out the submission form by July 12th with details and a 2–5-minute video showcasing your Solution impact. (Please let us know you're coming to PPCC, too!)After review by a panel of Microsoft judges, the top storytellers will be invited to present a virtual demo presentation to the judges during early August. You’ll be notified soon after if you have been selected as a finalist to share your story live at PPCC’s Got Power!  The live show will feature the solution demos and storytelling talents of the top contestants, winner announcements, and the opportunity to network with your community.  It's not just a showcase for technical talent and storytelling showmanship, show it's a golden opportunity to make connections and celebrate our Community together! Let's make this a memorable event! See you there!   Mark your calendars! Date and Time: Thursday, Sept 19th Location: PPCC24 at the MGM Grand, Las Vegas, NV 

Tuesday Tip | Accepting Solutions

It's time for another TUESDAY TIPS, your weekly connection with the most insightful tips and tricks that empower both newcomers and veterans in the Power Platform Community! Every Tuesday, we bring you a curated selection of the finest advice, distilled from the resources and tools in the Community. Whether you’re a seasoned member or just getting started, Tuesday Tips are the perfect compass guiding you across the dynamic landscape of the Power Platform Community.   To enhance our collaborative environment, it's important to acknowledge when your question has been answered satisfactorily. Here's a quick guide on how to accept a solution to your questions: Find the Helpful Reply: Navigate to the reply that has effectively answered your question.Accept as Solution: Look for the "Accept as Solution" button or link, usually located at the bottom of the reply.Confirm Your Selection: Clicking this button may prompt you for confirmation. Go ahead and confirm that this is indeed the solution.Acknowledgment: Once accepted, the reply will be highlighted, and the original post will be marked as "Solved". This helps other community members find the same solution quickly. By marking a reply as an accepted solution, you not only thank the person who helped you but also make it easier for others with similar questions to find answers. Let's continue to support each other by recognizing helpful contributions. 

Users online (3,653)