This is part 5 of the series “Send Power BI Report in Email using Power Automate“. In this post, we will create a flow that will run when a new email arrives in the inbox. We will save the attachment to a SharePoint location.
- Install Power BI Desktop
- Create a Simple Power Bi Report | Connect Power BI to SharePoint File
- Publish Power BI Report
- Send Power BI Report to Email | Subscribe to Emails
Follow previous parts to get an overview of this blog series.
Create the Flow
We will use a readymade template that allow us to save the attachment to a SharePoint location. Before that, create a new folder in SharePoint library where the attachments will be saved.
Go to flow.microsoft.com and login to your account. Click on templates and search for below template.
Give permissions by logging into the account.
Following flow will be auto created. We will make some modifications to it for our requirement.
If you remember, in our last part, we have subscribed the Power BI report where we have added the subject in the Subscription form. We will use the same subject to differentiate all the attachments.
On new email with attachment
Open “On new email with attachment” step in the flow. Choose the folder as Inbox and give the subject as “Financial Report – “. Leave all other fields as default.
If you are using “From” email filter in the first step, update the value to “true” in the next step. Otherwise, keep it as false.
For our requirement, I will delete this step. Also, take out the Condition -> If No -> Apply to Each step and put it after the first step and then delete the Condition step. You can drag and drop steps using the mouse.
Create file in SharePoint
Choose the SharePoint Site from the dropdown and select the folder which you created to save the attachments.
Save the flow and Test it manually. For that, go to Power BI report, open the subscription form and click on Run Now.
When flow run is successful, open the folder in SharePoint library and check the attachments added. You will notice that, there are two attachments saved there. First one is your report attachment and second one is some random file. To save only the report attachment, we will have to make some modifications to our flow.
Initialize string variable with value as name of the attachment. You can hardcode this value because this will be static and same name as of Report name and page name.
Add new condition inside the Apply to Each step. In this condition we are checking each iteration if attachment name is equal to the defined variable. Put other two steps inside If yes part.
Delete the files from SharePoint folder and rerun the flow. You will see that, now only 1 file is added in the SharePoint folder. In future, this file will be replaced if new file is added with the same name.
This completes our first flow. In the next part, we will make use of this saved attachment and send it in email body.