cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
R3dKap
Community Champion
Community Champion

Read CSV file and create/update list items with logic

Hi all,

 

I have a CSV file in a SharePoint Online library.

I'd like to create a FLOW that goes through each line of the CSV file and, using a bit of logic, create or update items in a list.

 

By example, if my CSV file is the following:

Last name;First name;Email

SMITH;Allan;a.smith@outlook.com

DOE;John;jdoe@outlook.com

 

If a have a list with the following:

Last name | First name | Email

DOE | John | john.doe@hotmail.com

 

When I run the workflow, I'd like to do the following:

  • when processing first line of CSV file (SMITH), since it does not exist in the list -> creates a new item in the list for SMITH
  • when processing second line of CSV file (DOE), since it already exist but email is different -> update list item to set new email for John DOE

The resulting list would then look like this:

Last name | First name | Email

DOE | John | jdoe@outlook.com

SMITH | Allan | a.smith@outlook.com

 

Is this possible ? Anyone already done something similar ?

 

Thanks for the help,

 

Emmanuel

1 ACCEPTED SOLUTION

Accepted Solutions
v-xida-msft
Community Support
Community Support

Hi @R3dKap,

 

Do you want to retrieve data from a CSV file stored in your SharePoint library using Microsoft Flow?

 

If you want to retrieve data from a CSV file stored in your SharePoint library using Microsoft Flow, I afraid that there is no way to achieve yourt needs in Microsoft Flow currently. There is no way to analyze a CSV file within Microsoft Flow currently, if you would like this feature to be added in Microsoft Flow, please submit an idea to Flow Ideas Forum:

https://powerusers.microsoft.com/t5/Flow-Ideas/idb-p/FlowIdeas

 

But you could consider take a try to convert the CSV file into a Excel file manually and then retrieve data from the Excel file within your flow. I have made a test on my side and please take a try with the following workaround:

 

I have created a CSV file in my SharePoint library and the data structure of it as below:14.JPG

I also created a SharePoint list on my side, the data structure of it as below:15.JPG

 

If you have converted your CSV file into a Excel file manually, please take a try with the following workaround:

  • Add a proper trigger, here I use Flow button trigger.
  • Add a "Get rows" action, File name field set to Id dynamic content of the "Create file" action, Table name field set to Table1 as a custom value.
  • Add a "Apply to each" action, input parameter set to output of "Get rows" action.
  • Within "Apply to each" action, add a "Get items" action, specify Site Address and List Name. The Filter Query field set to following formula:

 

Last_x0020_name eq 'item(...)' and First_x0020_name eq 'item(...)'

The first item(...) expression read as below:

 

 

item()?['Last name']

The second item(...) expression read as below:

 

 

item()?['First name']

Note: The above item(...) is wrapped with a single quotes.

 

 

Add a Condition, click "Edit in advance mode", type the following formula:

 

@empty(body('Get_items')?['value'])

 

Within "If/yes" branch of Condition, add a "Create item" action, specify Site Address and List Name. Last name field set to following formula:

 

item()?['Last name']

First name field set to following formula:

 

 

item()?['First name']

Email field set to following formula:

 

 

item()?['Email']

 

Within "If/no" branch of Condition, add a "Apply to each 2" action, input parameter set to output of "Get items" action. Within "Apply to each 2" action, add a "Update item" action, specify Site Address and List Name, Id field set to ID dynamic content of "Get items" action, Email field set to following formula:

 

items('Apply_to_each')?['Email']

 

Image reference:16.JPG

 

17.JPG

 

The flow works successfully as below:18.JPG

 

19.JPG

 

 

 

Best regards,

Kris

 

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

View solution in original post

12 REPLIES 12
v-xida-msft
Community Support
Community Support

Hi @R3dKap,

 

Do you want to retrieve data from a CSV file stored in your SharePoint library using Microsoft Flow?

 

If you want to retrieve data from a CSV file stored in your SharePoint library using Microsoft Flow, I afraid that there is no way to achieve yourt needs in Microsoft Flow currently. There is no way to analyze a CSV file within Microsoft Flow currently, if you would like this feature to be added in Microsoft Flow, please submit an idea to Flow Ideas Forum:

https://powerusers.microsoft.com/t5/Flow-Ideas/idb-p/FlowIdeas

 

But you could consider take a try to convert the CSV file into a Excel file manually and then retrieve data from the Excel file within your flow. I have made a test on my side and please take a try with the following workaround:

 

I have created a CSV file in my SharePoint library and the data structure of it as below:14.JPG

I also created a SharePoint list on my side, the data structure of it as below:15.JPG

 

If you have converted your CSV file into a Excel file manually, please take a try with the following workaround:

  • Add a proper trigger, here I use Flow button trigger.
  • Add a "Get rows" action, File name field set to Id dynamic content of the "Create file" action, Table name field set to Table1 as a custom value.
  • Add a "Apply to each" action, input parameter set to output of "Get rows" action.
  • Within "Apply to each" action, add a "Get items" action, specify Site Address and List Name. The Filter Query field set to following formula:

 

Last_x0020_name eq 'item(...)' and First_x0020_name eq 'item(...)'

The first item(...) expression read as below:

 

 

item()?['Last name']

The second item(...) expression read as below:

 

 

item()?['First name']

Note: The above item(...) is wrapped with a single quotes.

 

 

Add a Condition, click "Edit in advance mode", type the following formula:

 

@empty(body('Get_items')?['value'])

 

Within "If/yes" branch of Condition, add a "Create item" action, specify Site Address and List Name. Last name field set to following formula:

 

item()?['Last name']

First name field set to following formula:

 

 

item()?['First name']

Email field set to following formula:

 

 

item()?['Email']

 

Within "If/no" branch of Condition, add a "Apply to each 2" action, input parameter set to output of "Get items" action. Within "Apply to each 2" action, add a "Update item" action, specify Site Address and List Name, Id field set to ID dynamic content of "Get items" action, Email field set to following formula:

 

items('Apply_to_each')?['Email']

 

Image reference:16.JPG

 

17.JPG

 

The flow works successfully as below:18.JPG

 

19.JPG

 

 

 

Best regards,

Kris

 

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

Hi @v-xida-msft,

 

Thanks a lot for all your explanations... It's funny because I ended up doing exactly what you propose : I converted manually my CSV file to an Excel file with a table containing my CSV content. I then built my flow on this Excel file and of course it was much easier.

 

Cheers,

Emmanuel

2 potential problems by converting to Excel...

 

1. Limit of 1 million rows

2. Using Excel in flow doesn't support dynamics path and filename, you have to select the file within flow.  This defeats the purpose of having a library where a flow fires when a new file being added.  Highly frustrating...

R3dKap
Community Champion
Community Champion

Well, on my side I'll never get to the million records...

 

On the other hand, I totally agree wih you @asdfaf4 about the fact that Excel file paths cannot be dynamic and that's really a pain... Hope this feature will come true one day...

You can use Parse CSV action from Plumsail Documents connector. It allows you to convert CSV into an array and variables for each column. Please read this article demonstrating how it works.

 

Then you can iterate through result array and create items in a SharePoint list according to your logic.

Anonymous
Not applicable

The feature is not available right now. I had a similar issue where I paste my csv in a SharePoint folder and I managed to build a workaround.

1. Create an Excel file.

2. Use PowerQuery to read the csv from the Sharepoint.

3. Use flow to to read the queried table in Excel.

4. Update/Replace the Csv as required.

 

Cheers,

Aamir

 

Anonymous
Not applicable

can i set the power query to run twice a day?

Anonymous
Not applicable

Using Shell Scripts you can. Unfortunately there is no such feature in Flow yet. I use VBA macros but that involves manual intervention.

 

Cheers,

Aamir

for problem #2 you can use a flow trigger "when file is created"

SergiPino_0-1602764100279.png

then check if this file is the csv converted into .xlsx and if it's the case fire the rest of the flow.

 

I did this on other flows and works like a charm.

takolota
Multi Super User
Multi Super User

Hello,

 

Please see this template if you want to parse a CSV without 3rd party connectors. It works even if there are commas in the data.

 

https://powerusers.microsoft.com/t5/Power-Automate-Cookbook/CSV-to-Dataset/td-p/1508191

 

For this use-case, you can insert a Filter array action after the last Select action to filter the Select output before parsing the JSON to dynamic content.

Hi, I'm trying to use your solution but I get a strange behavior: the first 5 rows in Sharepoint list have one field empty while all the others show correctly the field value. I tried to re-run the flow starting from the same excel to update the values and I get the same result.

 

I checked the input and output of every step of the flow and I can find the correct value in the correct field but not in the Sharepoint list. The excel file is correct, the value in this rows are formatted correctly and are all plain text.

 

Any idea?

Hi, I'm trying to use your solution but I get a strange behavior: the first 5 rows in Sharepoint list have one field empty while all the others show correctly the field value. I tried to re-run the flow starting from the same excel to update the values and I get the same result.

 

I checked the input and output of every step of the flow and I can find the correct value in the correct field but not in the Sharepoint list. The excel file is correct, the value in this rows are formatted correctly and are all plain text.

 

Any idea?

Helpful resources

Announcements

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 (5,864)