Skip to main content
Community site session details

Community site session details

Session Id : uS423CgLG5uVr8JSNKIAoN
Power Automate - General Discussion
Unanswered

Apply to each Action failed moving file between folders and renaming

Like (0) ShareShare
ReportReport
Posted on 3 May 2024 12:36:56 by 10

The flow gets triggered after mails arrive into a specified shared folder. All attachments are saved in one folder and later moved into a different one. The flow seems to be working (files are renamed and placed on the final location).

However, it fails for some unknown to me reason. I tried a solution from a different post with an array, but it didn't work. I would actually like to add more parallel branches with conditions for different files, but this "Apply to each" seems to be the bottleneck. 

Naomilena_0-1714739401073.png

 

Also good to mention that this flow worked well with one condition. It can be noticed that there are two actions named "list folder", where the second one is the target folder and I didn't use it in the flow. Hence, deleted. 

Naomilena_1-1714739681639.png

 

If anyone could help me out, I would be grateful. 

Categories:
  • Naomilena Profile Picture
    10 on 07 May 2024 at 13:00:48
    Re: Apply to each Action failed moving file between folders and renaming

    10 files arrive daily to a shared mailbox.
    "NTCaCheckExternal.TXT" needs to be downloaded and renamed as "NTCaCheckExternal_ddmmyyyy", where the date is the previous working day.
    After being renamed it needs to be saved to a SP location.

    "Detail_by_Account_yymmdd.XLS" needs to be downloaded and renamed as "Detail_by_Account_yymmdd.CSV" and saved to a different SP location.

    "Income Receivable.XLS" needs to be downloaded and renamed as "Outstanding_yymmdd.csv" and saved to the third SP location.

     

    Till now I created the flow as shown above, where I saved all files in one location and then renamed and transferred them to another. The flow is not very efficient. I will be very grateful if you can suggest a better solution. I could not find any useful videos/sources online to solve my problem.

  • Naomilena Profile Picture
    10 on 06 May 2024 at 18:50:13
    Re: Apply to each Action failed moving file between folders and renaming

      Hi @creativeopinion 

     

    Answering your first question:

    List folder is the first SP location, where the files are saved. Compose 1 is the logic for giving a file a t-1 (previous working day) name. 

     

    This is my function: 

    if(equals(dayOfWeek(utcNow()),1),addDays(utcNow(),-3), if(equals(dayOfWeek(utcNow()),2),addDays(utcNow(),-1), if(equals(dayOfWeek(utcNow()),3),addDays(utcNow(),-1), if(equals(dayOfWeek(utcNow()),4),addDays(utcNow(),-1), if(equals(dayOfWeek(utcNow()),5),addDays(utcNow(),-1), null))))) 

    Users may sometimes refer to this location, but it is indeed not strictly necessary. This first location is used for control purposes (to make sure the flow works) and to avoid sending files to wrong locations. In the future I hope that users will refer to this folder rather than a shared mailbox. Also I didn't know how to build the flow otherwise, since there are 10 files in total and only 4 need to be moved to a specified location.

     

    Answering your second question: 

    Get the file content using path takes a file from the first SP location and Create file leads to the destination map, where the file name is

    "the name +formatDateTime(outputs('Compose_1'),'yyMMdd')  +csv"

    or txt file depending on the result I need for each specific case. 

     

  • creativeopinion Profile Picture
    10,468 Super User 2025 Season 2 on 06 May 2024 at 15:43:11
    Re: Apply to each Action failed moving file between folders and renaming

    @Naomilena It's still unclear to me what's happening in this part of the flow. You've indicated above that once they are saved to the SP location, users have to check the content. Can you clarify what this means?

     

    I need you to provide me additional insight as to how the flow knows which location to move the files to. Can you also provide insight on what you mean by modifying the name/file format?

     

    creativeopinion_0-1715009818722.png

     

  • Naomilena Profile Picture
    10 on 06 May 2024 at 15:33:22
    Re: Apply to each Action failed moving file between folders and renaming

    @creativeopinion 

    The flow gets triggered after files are delivered to a shared mailbox. They are saved to a sharepoint location, where they can be accessed by the users that need to check the content.

     

    Next to this permanent location they need to be placed (with a modified name/file format) on a specified location (a sharepoint folder), from which these files get automatically transferred into a different work environment. Files that are placed there are permanently removed from that folder. 

     

    Hope it clarifies! 

  • creativeopinion Profile Picture
    10,468 Super User 2025 Season 2 on 06 May 2024 at 15:13:32
    Re: Apply to each Action failed moving file between folders and renaming

    @Naomilena I'm not understanding the logic for your flow. Could you explain what is going on in your flow after you've created the files? What's the reason for moving files, instead of saving them in their intended location based on the condition? 

     

  • Naomilena Profile Picture
    10 on 06 May 2024 at 14:50:27
    Re: Apply to each Action failed moving file between folders and renaming

    Hi @creativeopinion ,

     

    Thank you very much for your reply. It's one of your videos that taught me how to download files from a shared mailbox. I've watched your video on referencing data as well. However, it's not very clear to me how I can list all files in a folder after the files are placed there and search within that folder. 

     

    You see, the first "Apply to each" box" already saved 10 files on the first location. Now I need to identify the files i need and move them to a different folder. That's why I list the original folder and then add a compose action to modify the name of the file later on. I'm trying to use the "SELECT" and "Filter array" like you showed in the video, but it's not really working. Btw, I also don't have the feature to rename my actions. I tried clicking everywhere: the dots, right button of the mouse and so on. 

    Naomilena_0-1715006993186.png

     

    I hope you will add more videos on that in the coming future. 

     

     

  • creativeopinion Profile Picture
    10,468 Super User 2025 Season 2 on 03 May 2024 at 14:20:39
    Re: Apply to each Action failed moving file between folders and renaming

    @Naomilena You should rework the logic in your flow as the way it's currently set up is inefficient. You've duplicated the actions in this section of your flow. I understand that you want to save them to different locations based on the file, however this would be really inefficient if you are doing this for multiple conditions.

    creativeopinion_0-1714745837277.png

    Instead, it would make more sense to create a matrix of some sort in either an Excel Table or SharePoint list and use that as a "look up" to check and see which folder(s) your files need to be saved to. This would make it a lot easier to manage and improve the efficiency of your flow. 

     

    In the meantime, check out these tutorials to learn some concepts you will need to learn for your flow:

    In the meantime, you might find these two YT Tutorials helpful: Are you using the Microsoft Power Automate Filter Array Action wrong?

    In this video tutorial I’ll show you 3 practical ways to use the Filter Array action and how to use it properly.

     

    1️⃣ Cross-Referencing Data

    2️⃣ Filtering by Key

    3️⃣ Substring Matching

     

    Did you know that the Condition action has a limit of 10 conditions? Although it might look like the Filter Array action can only accept one condition—this is not true. By using the advanced mode you can enter multiple conditions into a Filter Array action with an expression.

     

    IN THIS VIDEO:

     3 Ways to Use the Filter Array Action

     How to use the Scope Action to Group Actions

     How to Check the Number of Items returned from a Filter Array Action

     How to Cross-Reference Data in Excel with a SharePoint List

     How the Filter Array Action Works

     How to Access the Dynamic Content from a Filter Array Action

     How to Filter Items by a Key

     How to Filter Items by Matching a Substring

     How to Use Multiple Conditions in a Filter Array Action

     

    ---

     

    3 Mistakes YOU 🫵 are Making with the Apply to Each Action in your Microsoft Power Automate Flow

     

    In this video tutorial I’ll go over how to avoid these common mistakes when using the Apply to Each action in a Power Automate flow:

     

    1️⃣ Looping through a Single Item

    2️⃣ Creating Unnecessary Nested Loops

    3️⃣ Looping through an Unfiltered Array

     

    At the end of the video I share a few helpful insights when it comes to using the Apply to Each action in your flow.

     

    IN THIS VIDEO:

     How to avoid the Apply to Each action with a single item array

     How to use the item() function to access dynamic content in an array

     How to prevent unnecessary nested Apply to Each action loops

     How to use the Select action

     How to convert an array to a string with the Select action

    How to use the Filter Query field

     How to count the number of items in an array

     How to use a condition control

     How to use the concurrency control

     How to set a top count

     How to use Compose actions for troubleshooting

     

    Hope this helps!

    If I helped you solve your problem—please mark my post as a solution .
    Consider giving me a 👍 if you liked my response!

    👉 Level up your Power Automate skills by checking out my tutorials on YouTube
    👉 Tips and Tricks on TikTok and Instagram

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Telen Wang – Community Spotlight

We are honored to recognize Telen Wang as our August 2025 Community…

Announcing our 2025 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for…

Congratulations to the July Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
Tomac Profile Picture

Tomac 986 Moderator

#2
stampcoin Profile Picture

stampcoin 699 Super User 2025 Season 2

#3
Riyaz_riz11 Profile Picture

Riyaz_riz11 577 Super User 2025 Season 2