How do I refresh an Excel Power Query using Power Automate Online? - excel

I have data being pulled from a SharePoint list to an Excel file and I'm trying to use Power Automate online to create a scheduled flow that will trigger the "Refresh All" button for Power Query in Excel (see image). Due to different protections, I'm unable to simply schedule the refresh directly in Power Query in Excel and Power Automate cannot pull the SharePoint list in the format I need. There doesn't seem to be an option in Power Automate online that would connect to Power Query in Excel. Any suggestions?
Power Query Button

Power Automate doesn't have a feature to allow you to refresh connections or open/close a document. I was also encountering the issue of the document not refreshing on "open" because it was locked by another user (due to using One Drive). I couldn't use Power BI, scripts, or MACROS either.
I needed my workflow to add rows to a spreadsheet, update the pivot tables, and then send an email with the results. Here is what I did to get around the pivot tables not updating.
In Excel:
Open the pivot table options and select "Refresh data on file open".
Refresh Data
On the worksheet with your pivot table(s), create a table in a cell that has similar information as below (in the workflow we will update this table so it forces the system to re-open the document and refresh). Once the table is created, select the column and "Hide columns".
Updated Column
If you are using One Drive or a shared document like I did, when you have made all the changes you need, you will want to change the session to "viewing", and then close the document. 
*Any time you make changes manually in the document, make sure to "close" the session by changing it to "viewing" or else the workflow will not complete properly due to the doc being locked.
Viewing
In Power Automate: I have my trigger set to a schedule at the end of the month but your trigger or schedule and parameters can be whatever you set them as. I'm going to show you the steps that are important to the spreadsheet.
*Workflow snapshot:
Workflow Snapshot
Add a row into a table > Select the file location and the table > Update all the fields from the SharePoint list (Value= outputs('Get_items')?['body/value'].
I used this step to update the spreadsheet automatically with items added to a SharePoint list (so it can be extracted into a report monthly).
Add A Row
Delay 1: 10 minutes. This allows One Drive time to close and end the current session.
Update a row: Select the location of the file (this is the table we created and hid earlier).
Update Row
Delay 2: 2 Minutes
Get file content (One Drive) > Select the file. I was limited to only being able to see my individual One Drive so make sure your excel workbook is saved in a location you can select in Power Automate.
Convert file (One Drive)> Select the file. 
Convert File
Send an email > Attachment Name: (File Name= outputs('Convert_file') > Attachment Content: (Body= outputs('Convert_file'). It may be listed as "File content" in the Converted File section.
Send Email

There may be a simpler option if there is a way to refresh power query from Power Automate, or if you could use Power BI which is connected to Power Automate.
But there is also dataflows in Power Automate that can work similar to power query.
https://youtu.be/8IvHxRnwJ7Q
Then you can do any additional transformations in Power Automate & use Excel batch actions to import all the data to Excel from a flow.
https://powerusers.microsoft.com/t5/Power-Automate-Cookbook/Excel-Batch-Create-Update-and-Upsert/td-p/1624706

Related

How can I write back to source excel files when I get Excel data from data tab?

So, I want to create one Excel file each for every manager with only one single sheet and place it on OneDrive.
In order to get the data in one place, I am creating another excel file called combined.xlsx.
Now, I can export each workbook to a tab using Data -> Get Data -> From File -> From Workbook .
This is great so far. So, I can read data of 10 excelfiles on 10 sheets in combined.xlsx.
Now, I want to modify contents of one of the tabs and make sure it is reflected to the original file. How can I do this?
To elaborate on why it is not possible, you need to understand how Power Query deals with data:
You load your data into Power Query via the "Data" tab. The source can be anything Microsoft allows.
You then manipulate the data any which way in Power Query.
As a last step, you decide if and where to load the results. If you only want to create a connection to the query, you select "Close and Load to", which appears after you click on the arrow next to "Close and Load", and you pick that. Otherwise, the only other options are loading the query results to a table, PivotTable report, PivotChart.
Because the output sheets you have are connected to the query that produced them, any time you refresh the query, whatever manual changes you have made in the table that the query created originally will be wiped out and overwritten with the refreshed data.
If you were able to write back to the source here, you'd in effect
create a circular reference.
Check out this article about having Power Query output your data after manipulating it, maybe it helps.

Can I use a database built in SharePoint for data validation in an Excel spreadsheet?

I have a dataset that is being built in SharePoint that contains data including job codes, dates, descriptions, and other variables. I want to limit data entry in an Excel spreadsheet to only values in the SharePoint dataset. Possible? Well I know it's possible.. but HOW?!
You can export the SharePoint list into Excel. Click the Export to Excel command in the SharePoint list.
That will download or open a query file. If it only downloads, double click to open the file with Excel. Enable data connections when prompted.
Confirm that the data should be loaded into a new workbook, or, if you already have a prepared file open, use that and load the data into a new worksheet.
When you do that, a dynamic data connection is created. This data connection can be configured to refresh each time the workbook is opened. Data Ribbon > Queries & Connections > Right click the query in the query panel > Properties
You can then use the query data for the data validation.

Power Query/ Excel - automated query refresh

I have introduced several Excel files in the company, which use Power Query to consolidate different Excel files and prepare them accordingly. The structure is as follows:
1st file:
- Query from Access
- Querys from 3 Excel files
2.-5.Datei:
Various Excel files.
Some of these files are updated daily with new records.
That means I have to daily in the excel files with the queries and these update.
Is it possible to outsource this somehow?
Sharepoint, server?
What ideas do you have?
Except a VBA macro which opens and refreshes the data accordingly?
Best regards
If you have one file with Power Query that get data from multiple files with daily refreshed data without any Power Query in them then:
In file with Power Query when you add result of Power Query to sheet you will get connection.
You can customize this connection to refresh on workbook opening or every N minutes.
Is this is what you want ?
Here:
http://www.excel2013.info/power-query/automatic-update/
you can see in "Refresh the connection" section how to customize connection.
Refresh the connection
Because your data is in a table, your table is link to your source of data. When you will receive a new csv file with the same name, in the same folder, you just have to refresh the query to update your workbook or you can refresh automatically your table when you open your workbook. To do that, you have go to the menu Data > Connections
In the dialog box Workbook connections, you select one of the connections of your workbooks (here there is only one connection) and you click on Properties …
Select the option Refresh data when opening the file
Don’t forget to save and close your file.
If you have multiple files with Power Query and one file get data from another files results of Power Query then you can schedule some code to refresh connections. You can create Console App (C# language), add some library to work with Excel, get target files, open its workbook, refresh connections.
Like here:
https://social.msdn.microsoft.com/Forums/vstudio/en-US/b288098d-d4e8-4845-ae3f-38ad235e22aa/how-to-execute-a-quotrefresh-allquot-for-excel-programmatically-in-c?forum=csharpgeneral
Open Excel File, Refresh Query and Save C#
This way multiple files with Power Query will have always updated results of Power Query.
And your one main file with Power Query that get data from results of Power Query from this multiple files will have always updated data.

Using a JIRA saved filter with REST API and Excel

I have a report that I need to update in Excel many times a day using statistics from JIRA. If I can import these directly with code I would save a lot of time and effort.
Is it possible to use a saved JIRA filter in conjunction with the REST API function to import the results to Excel using a VBA macro?
This is a solution does not use REST API, but it may work for you. This is a workaround I am using so far and it works:
Run the Filter in Jira
Export the result list into an excel file using the Export CSV file with the option current field (to avoid having unnecessary fields) and with the right button of mouse select: Open in a new window
Now you will see the URL associated with your filter in a new window of your browser. Your filter is represented by a Filter ID, therefore the query will be always the same.
Go to excel and use the URL as a hyperlink
Every time you click on the hyperlink it will download the file from Jira. You need to have a Jira open sesion in your browser.
Create a VBA marco that click on the hyperlink for downloading the file.
Use Power Query for example for loading the file from the download folder location into a worksheet. Power Query is a new excel feature. Power Query is an ETL tool integrated into excel for loading files and processing them.
The steps 6-7 automates the process. Run the Marco for downloading the file and refresh the content of your worksheet from Data Connection. You can have an additional macro that refreshes the content of the worksheet. It refreshes all pivot tables and the file connection for reading the file.
Hint: Use excel Table for keeping the information updated automatically when additional information is loaded into the worksheet. If you use pivot tables for presenting the data, use as data source an excel table instead of excel range.
It minimizes a lot the manual effort.
Here you can find a solution that uses REST API, the author provides the source code, but it is more complicated. If you need something simple, my solution may work for you.

Excel 2010 Macro to do the same task again and again

I need to send Sales Report to my colleagues on the end of every week and I pull the same details from SAP (Stockwarehouse Russia). My question is, everytime I need to do the same steps again and again in Excel i.e. editing and deleting the same columns, applying filters, assigning the right description for the exact same fields, Movement Type etc. And it becomes very monotonous and pathetically time consuming.
So is there a way where I can record the steps I performed and store is somewhere on the HDD so that next time I can simply open Excel, run the program and report would be generated automatically?
What you will need to do is record a Macro
http://office.microsoft.com/en-gb/excel-help/create-or-delete-a-macro-HP010342374.aspx
http://www.dummies.com/how-to/content/how-to-record-a-macro-to-automate-tasks-in-excel-2.html
First 2 links in a Google search...
If you are using Excel 2013. I would higly recommend to use Microsoft Power Query AddIn (PQ). With PQ you can easily connect to SAP, than create some transformation with your data and save this as a "script". WHenever you open this worksheet you will have a fresh data. The adventage is that you don't need to use any piece of code and you can save your operation in few minutes.
Later if you will want to automate this operation you can write simple script (avaliable on the net) to refresh the worksheet and just add the code to send somewhere or if you have a SharePoint you can easily share with your worksheet with Power Query script into the SharePoint and everybody should have acces to your transormed data.
Please check: http://www.microsoft.com/en-us/powerBI/SAP.aspx#fbid=OjGdeZslbeu

Resources