“I use Power Automate to send emails with an HTML table, but it keeps sending them even when the table is empty, how can I avoid that?”
If you use Power Automate to send email reports or reminders, it’s a nice touch to format the data in an HTML table. It’s so much easier to read the data if it’s in a table. But what if there’s no data to display in the table? The flow will send the table anyway, but this time it’ll include only the table header. Such email doesn’t have any information value, and probably won’t make any recipient happy. If such situation happens, you shouldn’t send that email at all.
Check if the table is empty
Before you send an email, you should check if the table is not empty. And while it might look as a simple check, I’ve seen many times the same problem. Users very often add a condition to evaluate if the output from ‘Create HTML table’ is empty.
It’s the right condition, but using wrong dynamic content. The output from the ‘Create HTML action’ will never be empty. It’ll always contain the header, even if there’s no data to add.
That’s why you must go one step back. Back to the action that can return an empty value: the input of the ‘Create HTML table’. Check if it’s empty, and send the email only if it is not, e.g.
empty(outputs('Get_items')?['body/value']) <is not equal to> true
Summary
It’s always important to use the right dynamic content in the right situation. If you want to check if an HTML table is empty, you must check the output from the right Power Automate action. And it’s quite easy to identify which one it is, just check the flow run history. You’ll see that the ‘Create HTML table’ contains the table header, while the ‘Get items’ returns [] (= an empty array). That’s the action to check.
Hi, Is there a way to send the email outside of this condition. I want to have an email with multiple HTML tables, all of which only show if there is data present.
Hello Sam,
you can initialise a string variable and instead of sending an email append the HTML tables into the variable. Once it contains all the table you can send it in the body of the email (if the whole variable is not empty).
Hi Tom,
How to include only columns containing value in HTML table? I have several columns in my HTML table but not all columns have value. How to filter out the empty columns and only include the ones containing value in my HTML table?
Hello Ramisa,
that’s an interesting idea. I never did that so I can’t tell you how it’s done, but I’ll add it to my list of potential articles.
Hi i created table based on grouping of status and due date if records does not have either of status within week it is sending mail no records found but if records of only one status exist it is creating table for both status how to avoid creating table for other status does not have record
Hello Pooja,
as the article explains, if you don’t want to create a table you’ll need a condition to check whether the table input is empty. I’d split it into two table, one for each status, and create each of the tables only when they’re not empty.
He tom please reply