In the video tutorials for how to send a basic HTML table from Power BI with Power Automate and similar for styled tables, a question came up about what to do if the query to the Power BI dataset returned blank for a given user – if it has no rows to show, it will insert a blank table.
There’s a few ways to manage this, both involving “if” conditions – you can either use a conditional branch or you can write an if-statement into something that composes the thing you’re inserting in the email.
Either way, we need to make an expression that counts the number of rows in the array we are wanting to check. What you count here depends on whether you want to check if your entire query is blank, or just the array for a given user. Let’s do a count in a condition first, because that’s the most straightforward.
Count output rows in a conditional branch
Below is an example from the first flow link above where we’ve gotten a distinct list of our email recipients and are iterating through them to send them each an email with their rows in a table. We’re going to count the number of rows in the array for each user we’re looping over, and use that in a condition – if that count is >0, send an email with the embedded table. If it’s not, send an email letting them know they don’t have data to show. Here’s the expression text to count the rows in the array:
length(body('Filter_array'))
If you want to see the row count as an output in the flow history, you can drop the expression into a compose action, but it’s not strictly necessary.
Here’s the check for if it’s > 0:
If you are sending multiple data tables or attachments, you can add multiple conditions here, but if you want it to be a bit more dynamic you can put the if-check into the action that composes the email content, it will let you piecemeal creatively.
Option 2 – Use the compose action to check the row count and compose different email body content “chunks”
You can use if-statements in compose actions to compose content chunks for your email conditionally. This lets you insert the pieces, and each piece can independently be checking criteria and adding different content depending on the circumstance. This takes the place of the conditional branch above, so you’re only sending and maintaining one email action, not two in a branch – the difference is the content going into the email is more granularly controlled, so the email content is dynamic, not the action selection.
Here’s an example with one “chunk”, you can repeat with more compose actions for as many dynamic content pieces as you have (if you’re just embedding one table, you’ll only have one).
if(greater(length(body('Filter_array')), 0), body('Create_HTML_table'), 'You have no data this week!')
^ the above goes into a COMPOSE action. It will output the HTML table if there is a row count greater than 0, or “You have no data this week!” if there is no data. It goes after the create HTML table step, because that output needs to exist in order to insert it in this action.
Here’s what it looks like in context:
Since Power Automate is an open-ended tool, there’s 10 million ways to handle this – if you’re referencing the styled email video, you’d be writing an if-statement into the DAX that creates the HTML for the email. In this case, Power Automate is doing most of the HTML-lifting.