web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Automate
Answered

merge dataTable

(0) ShareShare
ReportReport
Posted on by 117

hi to all, i have 3 dataTable,  with the same structure, how i can put all inside DataTableFinal 

 

dataTable1

dataTable2

dataTable3

 

thanks in advance

  • CU16071609-1 Profile Picture
    6,255 Moderator on at

    @vincenzos1984_1 

     

    Please follow the below approach:

    Deenuji_0-1714212414506.png

     

    .Net script:

    Deenuji_1-1714212458844.png

     

    Deenuji_2-1714212501445.png

     

     

    Full code:

    Variables.CreateNewDatatable InputTable: { } DataTable=> dataTableFinal
    Excel.LaunchExcel.LaunchAndOpenUnderExistingProcess Path: $'''C:\\Boot\\Invoicecheck.xlsx''' Visible: True ReadOnly: False Instance=> ExcelInstance
    Excel.ReadFromExcel.ReadAllCells Instance: ExcelInstance ReadAsText: False FirstLineIsHeader: True RangeValue=> dataTable1
    Excel.LaunchExcel.LaunchAndOpenUnderExistingProcess Path: $'''C:\\Boot\\Invoicecheck1.xlsx''' Visible: True ReadOnly: False Instance=> ExcelInstance1
    Excel.ReadFromExcel.ReadAllCells Instance: ExcelInstance1 ReadAsText: False FirstLineIsHeader: True RangeValue=> dataTable2
    Excel.LaunchExcel.LaunchAndOpenUnderExistingProcess Path: $'''C:\\Boot\\Invoicecheck2.xlsx''' Visible: True ReadOnly: False Instance=> ExcelInstance2
    Excel.ReadFromExcel.ReadAllCells Instance: ExcelInstance2 ReadAsText: False FirstLineIsHeader: True RangeValue=> dataTable3
    Scripting.RunDotNetScript Language: System.DotNetActionLanguageType.CSharp Script: $''' dataTableFinal = new DataTable();
    
     // Merge all DataTables into the final DataTable
     dataTableFinal.Merge(dataTable1);
     dataTableFinal.Merge(dataTable2);
     dataTableFinal.Merge(dataTable3);
    
     // Convert the merged DataTable to a new DataTable using DefaultView.ToTable()
     dataTableFinal = dataTableFinal.DefaultView.ToTable();''' @'name:dataTable1': dataTable1 @'type:dataTable1': $'''Datatable''' @'direction:dataTable1': $'''In''' @'name:dataTable2': dataTable2 @'type:dataTable2': $'''Datatable''' @'direction:dataTable2': $'''In''' @'name:dataTable3': dataTable3 @'type:dataTable3': $'''Datatable''' @'direction:dataTable3': $'''In''' @'name:dataTableFinal': $'''''' @'type:dataTableFinal': $'''Datatable''' @'direction:dataTableFinal': $'''Out''' @dataTableFinal=> dataTableFinal

     

     

    How to copy/paste the above code into your PAD flow?

    Deenuji_3-1714212559756.gif

     


    Thanks,
    Deenuji Loganathan 👩‍💻
    Automation Evangelist 🤖
    Follow me on LinkedIn 👥

    -------------------------------------------------------------------------------------------------------------
    If I've helped solve your query, kindly mark my response as the solution ✔ and give it a thumbs up!👍 Your feedback supports future seekers 🚀

     

  • Nived_Nambiar Profile Picture
    18,138 Super User 2026 Season 1 on at

    Hi @vincenzos1984_1 

     

    Did you meant like this ?

     

    Assume i need to merge 3 datatables dt1,dt2 and dt3

    Nived_Nambiar_0-1714233852205.png

     

    Now merge it to final datatable dtFinal like below

    Nived_Nambiar_1-1714233879708.png

     

    Result would be -

    Nived_Nambiar_2-1714233896315.png

     

    Hope it helps !

    Thanks & Regards,

    Nived N 🚀

    LinkedIn: Nived N's LinkedIn
    YouTube: Nived N's YouTube Channel
    Blog: Nived Nambiar's Blogs

    🔍 Found my answer helpful? Please consider marking it as the solution!
    Your appreciation keeps me motivated. Thank you! 🙌

     

  • CU16071609-1 Profile Picture
    6,255 Moderator on at

    @Nived_Nambiar 

     

    This approach is truly impressive, and I wasn't aware that merging could be done this way. So, thank you for sharing that.

     

    I tested it with three rows of values across all three DataTables, but the merging doesn't seem to work correctly. Interestingly, it works perfectly when there's only a single row in each DataTable.

     

    Below is the code:

    SET dataTable1 TO { ^['Name', 'Phone', 'State'], ['Alice', '1234', 'AA'], ['Bob', '2345', 'BB'], ['Cindy', '3456', 'CC'] }
    SET dataTable2 TO { ^['Name', 'Phone', 'State'], ['David', '4567', 'DD'], ['Eva', '5678', 'EE'], ['Frank', '6789', 'FF'] }
    SET dataTable3 TO { ^['Name', 'Phone', 'State'], ['Grace', '7890', 'GG'], ['Henry', '8901', 'HH'], ['Ivy', '9012', 'II'] }
    SET dataTableFinal TO dataTable1 + dataTable2 + dataTable3




    Thanks,
    Deenuji Loganathan 👩‍💻
    Automation Evangelist 🤖
    Follow me on LinkedIn 👥

    -------------------------------------------------------------------------------------------------------------
    If I've helped solve your query, kindly mark my response as the solution ✔ and give it a thumbs up!👍 Your feedback supports future seekers 🚀

  • Verified answer
    Nived_Nambiar Profile Picture
    18,138 Super User 2026 Season 1 on at

    Hi @Deenuji 

     

    You are right, i just randomly thought about this approach and I have tested that, just tested with 3 or more rows as well , seems like it is taking one row from the dataable which is to be merged (i.e first row)

     

    Thanks & Regards,

    Nived N 🚀

    LinkedIn: Nived N's LinkedIn
    YouTube: Nived N's YouTube Channel
    Blog: Nived Nambiar's Blogs

    🔍 Found my answer helpful? Please consider marking it as the solution!
    Your appreciation keeps me motivated. Thank you! 🙌

     

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Automate

#1
Mohsin Ali Profile Picture

Mohsin Ali 414

#2
11manish Profile Picture

11manish 331 Super User 2026 Season 2

#3
M Bilal Khan Profile Picture

M Bilal Khan 274

Last 30 days Overall leaderboard