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 Platform Community / Forums / Power Automate / SQL Excel data from da...
Power Automate
Answered

SQL Excel data from datatables

(0) ShareShare
ReportReport
Posted on by Microsoft Employee

Hi,

I'm trying to read data from Excel File1 using SQL and paste selected columns from the query result to Excel File2. To make things a little trickier, there might be different column names, so I need to provide mapping (e.g. [Date] -> [DateAdded])

 

As I understand, I cannot open two Excel files with the same connection, so it seems I need to:

  1. Open connection to File1 
  2. Execute SELECT query to get data into datatable
  3. Close connection to File1
  4. Open connection to File2
  5. Do some magic SQL statement to insert query results from datatable
  6. Close connection to File2

Thanks in advance

I have the same question (0)
  • VJR Profile Picture
    7,635 on at

    Hi @Anonymous 

     

    I could not fully understand your requirements.

    Also, any specific reason you are not using Read from Excel1 and Write to Excel2 actions ?

  • momlo Profile Picture
    1,527 Super User 2024 Season 1 on at

    Hi @Anonymous 

    Whereas SQL Select is usually my preferable way of pulling data from Excel thanks to the ease of filtering, match etc, writing back I usually address with Write to excel @VJR suggested.

     

    Not sure what logic you are building, so not sure if this will be of any help for you, but what you could do is:

    Instead of two separate excel files, operate on 1 with 2 Sheets.

    In such case you can open 1 SQL connection and each sheet is treated as a separate table, so you can then execute usually SQL goodies such as table JOINs etc.

     

    But from what you wrote, you just need to pull data from file1, change column names, and paste it to file 2.

    So I would use something like this:

     

    1. SQL -> pull data from file 1, changing the column names to desired names at the same time, store it in %ExcelData% variable.

     

    Select [Date] AS [DateAdded], [AnotherColumn] AS [AnotherColumnAddes]

    FROM [SheetName$]

     

    2. Excel action (not excel) -> Paste data to file2 in a way you want to structure data

    If you need to paste the column headers, then write %ExcelData%.ColumnHeadersRow to the first row, and the %ExcelData% to row 2

  • Community Power Platform Member Profile Picture
    Microsoft Employee on at

    @VJR @momlo thanks for your suggestions. I wanted to use SQL because it is super fast.

    In the targe Excel to paste data from queryresult(datatable) I want to write an entire datatable column in one go. Do you if it is possible? I was trying Write to Excel Worsheet action with %SomeDataTable['ColumnName']% as a value to write, but it did not work

  • Verified answer
    VJR Profile Picture
    7,635 on at

    If you want to get only one column then you can use Retrieve data table column into list and write that list into Excel.

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

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
David_MA Profile Picture

David_MA 253 Super User 2026 Season 2

#2
11manish Profile Picture

11manish 172 Super User 2026 Season 2

#3
trice602 Profile Picture

trice602 134 Super User 2026 Season 2

Last 30 days Overall leaderboard