web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Error in Power Automat...
Power Automate
Unanswered

Error in Power Automate Flow: Invalid Variable Initialization and Filter Array Issues

(0) ShareShare
ReportReport
Posted on by

Description of the Problem:
I am trying to create a Power Automate flow that processes CSV files uploaded to a SFTP folder. The goal is to extract participant codes from each file and filter the data based on these codes. However, I am encountering issues with initializing a variable and using a Filter Array action correctly, leading to execution errors.

Current Setup:

  • Trigger: When a file is added or modified in a specific SFTP folder.
  • Action 1: Compose (to split the file content into an array of lines).
  • Action 2: Initialize Variable (named RowsByParticipantCode, type: Array).
  • Action 3: Apply to Each (on the output from the Compose action):
    • Action 3.1: Compose 1 (to extract the PARTICIPANT_CODE).
    • Action 3.2: Append to Array Variable (to add participant codes to RowsByParticipantCode).
    • Action 3.3: Filter Array (to filter based on PARTICIPANT_CODE).

Error Messages:

  • "The execution of template action 'Apply_to_each' failed: the result of the evaluation of 'foreach' expression '@outputs('Compose')' is of type 'String'. The result must be a valid array."
  • "The variable action 'Initialize_variable' of type 'InitializeVariable' cannot be nested in an action of type 'Apply_to_each'."

Steps Taken:

  1. Verified that the output of the Compose action is intended to be an array.
  2. Adjusted the Filter Array expression to reference the correct variable.
  3. Moved the Initialize Variable action outside of the Apply to Each loop to ensure it initializes once.

Additional Information:
I have attached screenshots of my flow, including the JSON structure of the actions and any error messages displayed in the run history.

Request for Help:
Can someone help me identify why the Apply to Each action is failing with a type 'String' error? Additionally, what is the best way to structure the flow to ensure that the Filter Array action works correctly and efficiently?

 

Any help would be greatly appreicated!

Categories:
I have the same question (0)
  • bscarlavai33 Profile Picture
    752 Super User 2025 Season 2 on at
    Try wrapping what you have in the Compose with "array()"

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 501 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 323 Moderator

#3
abm abm Profile Picture

abm abm 237 Most Valuable Professional

Last 30 days Overall leaderboard