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

Announcements

News and Announcements icon
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 2026 Season 1 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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the April Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
Vish WR Profile Picture

Vish WR 785

#2
Valantis Profile Picture

Valantis 669

#3
Haque Profile Picture

Haque 563

Last 30 days Overall leaderboard