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.
Hey, @KONeill102399 , all you should need to change is to make this:
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:
@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.
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 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.
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).
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]']
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.
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])
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.
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.
Add a send an email action to the YES branch. Insert the appropriate recipients and content.
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!
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.
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:
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.
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. 🙂
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.
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)
Each row might have a different action but I want the entire table to be sent each time.
Hi, @KONeill102399 , couple of things that I think that you might need:
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.
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:
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.
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.
WarrenBelz
146,731
Most Valuable Professional
RandyHayes
76,287
Super User 2024 Season 1
Pstork1
66,077
Most Valuable Professional