How to Create an HTML Table from an Array in Power Automate

Do you need to create an HTML table from an array of values in Power Automate?

An HTML table is a great way to present your data in a readable format within emails sent from your flows.

Power Automate has an action that will allow you to convert any array to an HTML table, but it’s not completely obvious how to use it to get the result you need.

This post will explore how to use the Create HTML table action to transform your simple arrays or arrays of objects into an HTML table.

Create an HTML Table from an Array of Values

["John","Mark","Amanda"]

The first scenario is when you have an array of values such as the above example.

The array contains a list of first names. This example will show you how to create a single column HTML table from these names with a column heading of Names.

Here are the steps needed to convert this simple array to an HTML table.

  1. Add the Create HTML table action to your flow.
  2. Add the dynamic content for the array into the From input.
  3. Click on the Show advanced options link. This will reveal the Columns input where you can select how the columns for your HTML table are described.
  1. Choose the Custom option for the Columns.
  2. Add the text for your column heading in the Headers column. In this example, the header should be Names.
  3. Add the expression @item() in the Values column for the corresponding header created in the previous step.

The item function will loop through each item in the array and add it to the HTML table.

Create an HTML Table from an Array of Objects

[
	{"first": "John", "last": "MacDougall"},
	{"first": "Mark", "last": "Wilson"},
	{"first": "Amanda", "last": "Thompson"}
]

The next scenario involves creating an HTML table from a more complex array of objects. This example shows an array of objects where each object contains two key-value pairs for first and last names.

Here you want to create an HTML table with multiple columns based on the key-value pairs in the objects of the array.

Here are the steps needed to convert this array of objects to an HTML table.

  1. Add the Create HTML table action to your flow.
  2. Add the dynamic content for the array into the From input.
  3. Click on the Show advanced options link to show the Columns input.
  4. Choose the Custom option for the Columns.
  5. Add the First Name for your column heading in the Headers column.
  6. Add the expression @item()['first'] in the Values column.

The item function will loop through each object in the array, then you can access the value in each key-value pair by referencing the key in square brackets at the end of the item function.

Now you can repeat the same for any other columns by adding more entries in the Headers and Values.

  1. Add the Last Name for your column heading in the Headers column.
  2. Add the expression @item()['last'] in the Values column.

This will create a two column HTML table with the column headings First Name and Last Name where the values are those from the objects in your array.

Conclusions

Creating HMTL tables within Power Automate is a useful way to make your data more presentable within any email.

Power Automate has a built-in method for converting any array to an HTML table. But unfortunately, it’s not very easy to use and it will require the use of the item function.

Have you needed to create HTML tables in your flows? How did you get the job done? Let me know in the comments!

About the Author

John MacDougall

John MacDougall

John is a Microsoft MVP and freelance consultant and trainer specializing in Excel, Power BI, Power Automate, Power Apps and SharePoint. You can find other interesting articles from John on his blog or YouTube channel.

Related Articles

Comments

1 Comment

  1. Mustaque Ali

    Thank you for the tip, it took some time to get into this page which helped me to convert the array into table. Appreciate that.

Get the Latest Tech Tips

Write For Us

Are you a tech enthusiast with a talent for writing great content? Come write for us!

Follow Us

Follow us on social media to stay up to date with the latest in tech!