cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Lyn0615
New Member

how to export data from sql connection to excel using powerapps

Hi everyone, I want to export data from sql to excel using powerapps. can anyone knows on how to do that. Thank you very much.

7 REPLIES 7
v-micsh-msft
Community Support
Community Support

Hi @Lyn0615,

 

I think here the better way is to use Microsoft Flow.

Using SQL->Get rows and then Excel->Insert Row should be able to "export " data from SQL Server to Excel.

Then add the flow into PowerApps.

Flow configuration as below:

49.PNG

Adding some article reference:

Start a flow in an app

 

Besides, this could also be done only within PowerApps, but there may be some limitation when working with all data due to delegation.

We could take use of Forall and the patch function to insert the record from SQL to Excel table. Formul should be similar as below:

Forall(
        '[dbo].[TableName]', 
        patch(ExcelTableName, 
                  defaults(ExcelTableName), 
                  {IdExcel:Id, ........}
                 )
   )

Please note that all the options would require Excel has a pre-defined table with the column name (better a little different from the SQL table column name) of the corrsponding SQL Table.

Some function reference:

Forall function in PowerApps

Patch function in PowerApps

 

Regards,

Michael

Community Support Team _ Michael Shao
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi ,

 

This is a great solution. But the critical issue may also be that:

We cannot often have the predefined table in Excel to export data. This may happen because we need to create one file export per filter in powerapps and send it via email as attachment, often with the filename based on the filter used.

 

As a workaround, we could do the following:

1. Create an excel template in a folder/one drive with all the columns to be exported .

2. Create a flow with the following steps:

  • Delete all rows in the template file
  • Export data based on filters (selected from powerapps) into this template
  • Copy this file into a new file with an appropriate filename (could be based on filter)
  • "Get File Content" of the new file
  • Send as attachment
  • Delete all rows from the template.

3. The excel template will just be a transitory file to get SQL data and allow us to send the actual data file as attachment.

Let me know if this solution works?

 

Thanks,

 

Hi
Many thanks for your post, I've seen ForAll() elsewhere but couldn't get it to work (in a different context).

 

However, I stumbled accross this post while looking for a way to export SQL data to Excel.

I can now take my colllated relational data (via a collection) and then save this out to an Excel spreadsheet (connected as a data source).

 

Not technically an export but perfect for what I need.

 

Cheers

Anonymous
Not applicable

Hi @GaryEden 

I have a similar requirement . 
Can you share any helpful link for us to have a look at the steps you used.

I need to create an excel out of the table and views stored in SQL .
Each table corresponds to one Excel sheet.

 

Regards

Ayush

Drrickryp
Super User
Super User

Hi all,

You Cannot create a table or modify the underlying structure of an existing table from within PowerApps. This is by design. The thought that a user could do that in one of my apps  would keep me up nights. You can create an Excel table connect it to PowerApps and fill it with data. 

Anonymous
Not applicable

Hi @Drrickryp 

I understand and you are correct.
I actually need a flow which can download SQL table as an Excel.
Then I can map that Flow to a button in powerapps.

Hi Ayush

I ended up saving out to a SharePoint list and then from this list saved out to Excel.
However, when you go to clear the old data you end up hitting the 500 row limit in PowerApp - you can increase the row limit to 2000 but it gets very, very slow and sometimes that still isn't enough.

 

In the end I abandoned trying to export from PowerApps to Excel (or anthing else) and started using PowerBI instead. This connects to the same SQL Database and can use the same stored proceedures as PowerApps if you want (I duplicated mine as I wanted to modify them a bit). PowerBI is set to update overnight and provides loads of options to slice and dice the data with colourful charts etc. If you need to export the raw data you can do this straight to Excel with a single click.

 

I hadn't used PowerBI before this, but it only took a few hours to understand the basics to replicate what I was doing via the PowerApps export to Excel process i.e. Pivot Tables. Worth the investment of time and the management team love having reports at their finger tips.

 

Cheers

Gary

Helpful resources

Announcements
Power Apps News & Annoucements carousel

Power Apps News & Announcements

Keep up to date with current events and community announcements in the Power Apps community.

Community Call Conversations

Introducing the Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Apps Community Blog Carousel

Power Apps Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Top Kudoed Authors
Users online (3,171)