Home > Enterprise >  How to create Excel rows from Dataverse using Power Automate?
How to create Excel rows from Dataverse using Power Automate?

Time:04-03

Can someone point me to a tutorial of how to create Excel rows from a Dataverse table using Power Automate? For example, I have a Dataverse table with one of the columns being "color". For every record with "blue", I want to add a row to an Excel file. I'm having a hard time finding a youtube or blog that explains this but I'm sure I'm just not searching well enough.

I've tried to connect to a Dataverse table but not sure how to loop it through all the rows. Also don't quite understand all the commands in the Dataverse filter, I'm used to PowerApps filters but getting used to eq and ne, etc..

CodePudding user response:

There are quite a few ways to achieve the result you want. I've gone for a relatively easy approach and one that should do what you want but depending on performance, etc. you may want to change it out for something else.

Firstly, I created a table in DataVerse with a few dummy fields, obviously, you just need to use your own table.

Here's the structure of the table so you have context and I've highlighted the additional fields that I want to pull out (along with the ID, Name and Created On) ...

Table

Now in my flow, I've added the Dataverse -> List rows action. Specifically, I have filtered the data to the cr160_color column for the value blue as you want to do based on your scenario.

List rows

The next step involves traversing the data retrieved from the table and writing it out to an Excel document on a SharePoint workspace that has a table (must be defined as a table) with the following fields.

Spreadsheet

This is the action step in the flow ...

Add rows to table

When it executes, I get my data ...

Result

If you run the flow again, it will double up all of the data so if you need to clear the table before loading again (you could always try updating or delta loading if you can be bothered) then you can inject a step before the loading of the data to clear the table.

You can do that with an office script. To do that, in Excel online, you should have a tab in the ribbon called Automate ...

Ribbon

In there, create a new script, call it Clear Table Data and add this code ...

function main(workbook: ExcelScript.Workbook, worksheetName: string, tableName: string)
{
  let worksheet = workbook.getWorksheet(worksheetName);
  let tableToClear = worksheet.getTable(tableName);

  let rowsToDelete = tableToClear.getRangeBetweenHeaderAndTotal().getRowCount();
  
  try {
    tableToClear.deleteRowsAt(0, rowsToDelete - 1);
  }
  catch { }
}

Now inject that step in your flow before it loads all of the data back in ...

Delete Row Data

This is the final flow ...

Flow

  • Related