cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Imke
Advocate IV
Advocate IV

Part 1: Automatically validate email attachments with a flow in Power Automate and Power BI

Receiving files from business partners that don't match the agreed requirements/formats causes all sorts of problems in daily business. I found it particularly disturbing during month-end closing when time is really tight: You have a strict rule in which order each process has to run and there are many dependencies between them. So when then one import doesn't work, many other processes will come to a halt as well. Fortunately, today there is a simple remedy for it: Automatically validate E-mail attachments with Flow and Power BI

 

Process Automation with Power Automate and Power BI

 

You can create a flow that "listens" for incoming emails in a mailbox that match certain criteria and contain attachments. The flow can then extract these attachments and save them to an online-folder. After that, Power Automate triggers a refresh of a Power BI dataset, that imports these attachments and checks for the data quality-criteria that you have defined. Then you create measures for the data quality that trigger data driven alerts from Power BI service. Flow then listens for these alerts and sends an email back to the sender, requesting for a corrected file.

 

This not just saves crucial time, but also your nerves (and those of your team-mates).

 

The Details

 

Trigger

 

Start a flow with a trigger that searches your mailbox for ingoing messages. There are different triggers available (also shared mailboxes or Gmail). Specify the criteria for which the attachments shall be checked to prevent unwanted emails being sent out to senders who are sending different attachments.

 

0_TriggerEmail.jpg

 

Actions

After this trigger, the first action has to be defined. The "Get email" action will just fetch the content of the email that triggered the flow. Only thing to do in this step is to choose the "Message Id" in the specified field and select to include attachments. 

 

1_GetEmail.jpg

The next action will be to extract the attachment(s) and save them in a dedicated folder. Therefore I'm using a "Apply to each"-action. I select "Attachments" as the output from the previous step and define the action that shall be performed on them:

 

2_ApplyToEachApply to each attachment

 

"Create file" saves each file to the folder path I'm defining in the first field. I select "Attachments Name" for the the File Name and the "Attachment Content" for File Content.

 

3_CreateFileCreate File

 

Power BI

 

Now that the files are stored, I import them to Power BI and create one or more queries that check the critical elements. These could be:

  • column headers match a defined list
  • dates are valid
  • only agreed product codes
  • …. basically everything

In this example I just check for valid dates: Convert the column "Dates" to dates, check it and keep rows with errors.

 

4_PowerBISelectRowsWithErrorsIn Power BI: Select rows with errors

 

I load the table to the datamodel and create a measure that counts the rows.

 

5_ErrorMeasureMeasure that indicates errors

 

 

This measure is placed in a card visual (as this is one of the few visuals, that is suitable to trigger a data driven alert in the service). This will be published to the Power BI service.

 

Power BI Service

 

In the service, I pin the card visual to a dashboard. From there I can configure a data driven alert: 

 

6_DataDrivenAlertData driven alert in Power BI

 

Back to Flow

Back in Flow, I create a trigger to refresh the dataset that we just created in the Power BI service. This is possible through a custom connector (Chris Webb describes here how to create one using an open API-definition. But if you're not so familiar with setting up custom connectors yet, I highly recommend Ida Bergums excellent walkthrough of how to do it manually. )

 

7_TriggerRefresh.jpgTrigger refresh of Power BI data set from Flow

 

By navigating to the dataset, I get the URL that displays the Id/Key for this task:

 

8_FetchGroupAndDatasetIDFetch group- and dataset-ID

 

After the dataset is refreshed, the Flow now gets a trigger that listens to data driven alert from Power BI. I have to select in the "Alert Id" from Power BI in there:

 

9_DataDrivenAlertTriggerData driven alert trigger from Power BI

In the last action I define the details of the email that shall be sent to the sender of the faulty attachments:

 

10_ReturnEmailReturn E-mail

Looks very straightforward, doesn't it?

 

Caveats?

 

Think again and check Part 2 of this series where I show the major error in this Flow and the missing elements that make this Flow really flow in a corporate environment.

 

0 REPLIES 0

Helpful resources

Announcements

Celebrating the May Super User of the Month: Laurens Martens

  @LaurensM  is an exceptional contributor to the Power Platform Community. Super Users like Laurens inspire others through their example, encouragement, and active participation. We are excited to celebrated Laurens as our Super User of the Month for May 2024.   Consistent Engagement:  He consistently engages with the community by answering forum questions, sharing insights, and providing solutions. Laurens dedication helps other users find answers and overcome challenges.   Community Expertise: As a Super User, Laurens plays a crucial role in maintaining a knowledge sharing environment. Always ensuring a positive experience for everyone.   Leadership: He shares valuable insights on community growth, engagement, and future trends. Their contributions help shape the Power Platform Community.   Congratulations, Laurens Martens, for your outstanding work! Keep inspiring others and making a difference in the community!   Keep up the fantastic work!        

Check out the Copilot Studio Cookbook today!

We are excited to announce our new Copilot Cookbook Gallery in the Copilot Studio Community. We can't wait for you to share your expertise and your experience!    Join us for an amazing opportunity where you'll be one of the first to contribute to the Copilot Cookbook—your ultimate guide to mastering Microsoft Copilot. Whether you're seeking inspiration or grappling with a challenge while crafting apps, you probably already know that Copilot Cookbook is your reliable assistant, offering a wealth of tips and tricks at your fingertips--and we want you to add your expertise. What can you "cook" up?   Click this link to get started: https://aka.ms/CS_Copilot_Cookbook_Gallery   Don't miss out on this exclusive opportunity to be one of the first in the Community to share your app creation journey with Copilot. We'll be announcing a Cookbook Challenge very soon and want to make sure you one of the first "cooks" in the kitchen.   Don't miss your moment--start submitting in the Copilot Cookbook Gallery today!     Thank you,  Engagement Team

Announcing Power Apps Copilot Cookbook Gallery

We are excited to share that the all-new Copilot Cookbook Gallery for Power Apps is now available in the Power Apps Community, full of tips and tricks on how to best use Microsoft Copilot as you develop and create in Power Apps. The new Copilot Cookbook is your go-to resource when you need inspiration--or when you're stuck--and aren't sure how to best partner with Copilot while creating apps.   Whether you're looking for the best prompts or just want to know about responsible AI use, visit Copilot Cookbook for regular updates you can rely on--while also serving up some of your greatest tips and tricks for the Community. Check Out the new Copilot Cookbook for Power Apps today: Copilot Cookbook - Power Platform Community.  We can't wait to see what you "cook" up!    

Welcome to the Power Automate Community

You are now a part of a fast-growing vibrant group of peers and industry experts who are here to network, share knowledge, and even have a little fun.   Now that you are a member, you can enjoy the following resources:   Welcome to the Community   News & Announcements: The is your place to get all the latest news around community events and announcements. This is where we share with the community what is going on and how to participate.  Be sure to subscribe to this board and not miss an announcement.   Get Help with Power Automate Forums: If you're looking for support with any part of Power Automate, our forums are the place to go. From General Power Automate forums to Using Connectors, Building Flows and Using Flows.  You will find thousands of technical professionals, and Super Users with years of experience who are ready and eager to answer your questions. You now have the ability to post, reply and give "kudos" on the Power Automate community forums. Make sure you conduct a quick search before creating a new post because your question may have already been asked and answered. Galleries: The galleries are full of content and can assist you with information on creating a flow in our Webinars and Video Gallery, and the ability to share the flows you have created in the Power Automate Cookbook.  Stay connected with the Community Connections & How-To Videos from the Microsoft Community Team. Check out the awesome content being shared there today.   Power Automate Community Blog: Over the years, more than 700 Power Automate Community Blog articles have been written and published by our thriving community. Our community members have learned some excellent tips and have keen insights on the future of process automation. In the Power Automate Community Blog, you can read the latest Power Automate-related posts from our community blog authors around the world. Let us know if you'd like to become an author and contribute your own writing — everything Power Automate-related is welcome.   Community Support: Check out and learn more about Using the Community for tips & tricks. Let us know in the Community Feedback  board if you have any questions or comments about your community experience. Again, we are so excited to welcome you to the Microsoft Power Automate community family. Whether you are brand new to the world of process automation or you are a seasoned Power Automate veteran - our goal is to shape the community to be your 'go to' for support, networking, education, inspiration and encouragement as we enjoy this adventure together.     Power Automate Community Team

Hear what's next for the Power Up Program

Hear from Principal Program Manager, Dimpi Gandhi, to discover the latest enhancements to the Microsoft #PowerUpProgram, including a new accelerated video-based curriculum crafted with the expertise of Microsoft MVPs, Rory Neary and Charlie Phipps-Bennett. If you’d like to hear what’s coming next, click the link below to sign up today! https://aka.ms/PowerUp  

Tuesday Tip | How to Report Spam in Our Community

It's time for another TUESDAY TIPS, your weekly connection with the most insightful tips and tricks that empower both newcomers and veterans in the Power Platform Community! Every Tuesday, we bring you a curated selection of the finest advice, distilled from the resources and tools in the Community. Whether you’re a seasoned member or just getting started, Tuesday Tips are the perfect compass guiding you across the dynamic landscape of the Power Platform Community.   As our community family expands each week, we revisit our essential tools, tips, and tricks to ensure you’re well-versed in the community’s pulse. Keep an eye on the News & Announcements for your weekly Tuesday Tips—you never know what you may learn!   Today's Tip: How to Report Spam in Our Community We strive to maintain a professional and helpful community, and part of that effort involves keeping our platform free of spam. If you encounter a post that you believe is spam, please follow these steps to report it: Locate the Post: Find the post in question within the community.Kebab Menu: Click on the "Kebab" menu | 3 Dots, on the top right of the post.Report Inappropriate Content: Select "Report Inappropriate Content" from the menu.Submit Report: Fill out any necessary details on the form and submit your report.   Our community team will review the report and take appropriate action to ensure our community remains a valuable resource for everyone.   Thank you for helping us keep the community clean and useful!

Users online (3,207)