Hello,
@ryule, @damien-mick in fact i discover today that you can use variable when you define or update datatable and it works for headers too !
I found the solution in this post : https://www.flowjoe.io/2022/04/12/add-variables-to-a-data-table-on-power-automate-desktop
The tips is to not add percent (%) and single quote (') before and after your datatable variable name.
For example i have done a web extract with a first datatable with table headers and second datatable with table data and i want to join these two datatables.
So i define a new datatable variablewith 9 headers issued from second column of first datatable named DataReportHeader.
So below the value of my new datable variable 'Report':
%{^[ReportHeader[0][1],ReportHeader[1][1],ReportHeader[2][1],ReportHeader[3][1],ReportHeader[4][1],ReportHeader[5][1],ReportHeader[6][1],ReportHeader[7][1],ReportHeader[8][1]]}%
Code to paste in PAD:
SET Report TO { ^[ReportHeader[0][1], ReportHeader[1][1], ReportHeader[2][1], ReportHeader[3][1], ReportHeader[4][1], ReportHeader[5][1], ReportHeader[6][1], ReportHeader[7][1], ReportHeader[8][1]] }
And after i can update this new datatable by adding data from second datatable named DataReport, here we iterate with foreach action and we update variable on each loop :
If you want to take specifics columns values, below the variable value :
%Report + [CurrentItem[1], CurrentItem[2], CurrentItem[3], CurrentItem[4], CurrentItem[5], CurrentItem[6], CurrentItem[7], CurrentItem[8]]%
Code to past in PAD with foreach loop :
LOOP FOREACH CurrentItem IN ReportData
SET Report TO Report + [CurrentItem[1], CurrentItem[2], CurrentItem[3], CurrentItem[4], CurrentItem[5], CurrentItem[6], CurrentItem[7], CurrentItem[8]]
END
Or if you want the complete row with all columns values :
%Report + CurrentItem%
Code to past in PAD with foreach loop :
LOOP FOREACH CurrentItem IN ReportData
SET Report TO Report + CurrentItem
END
Enjoy !