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 / Looking for help with ...
Power Automate
Answered

Looking for help with logic; what Im doing wrong

(0) ShareShare
ReportReport
Posted on by 6
Hi everyone, basically, Im trying to through each excel file in a sharepoint folder, if the file name contains "leader", and send a teams message with the file name and the number of rows. The issue with my current flow is that it keeps sending me the same number (58) over and over again. 
 
Here is my flow would love if someone can help out where Im going wrong!!
 
 
Filter array: "Name" Contains "Leader
 
Get file content: Site address, File identifier: items('Apply_to_each')?['{Identifier}']
 
Compose: split(body('Get_file_content'), decodeUriComponent('%0A'))
 
Compose 1: length(outputs('Compose'))
 
Pos message in a chat or channel
 
 
Categories:
I have the same question (0)
  • Suggested answer
    MichaelFP Profile Picture
    1,991 Moderator on at
    If want to know how many rows from an excel file, is to use excel actions, instead of using compose.
     
    You can use "List Rows present in a table" Excel Online (Business) - Connectors | Microsoft Learn, and get the number of rows.
     
    If my answer helped you, please give me a thumbs up (👍). If solve your question please mark as answer ✔️. This is help the community.
  • Verified answer
    creativeopinion Profile Picture
    10,508 Moderator on at

    The logic of your flow needs to be adjusted. In your case, there isn't a need for two Apply to Each actions—neither of them currently interact with each other. The first one is unnecessary as you can define a Filter Query to filter out the files you need right in the Get Files (properties only) action.

    Define a Filter Query

    Use the substringof opreator. In my example below I'm searching for files with 'form' in the file name. Note: When using the substringof operator—the string used isn't case sensitive. 
     
    Also, this action returns files and folders. To filter out files only you need to use FSObjType eq 1—to filter out folders only, use 0.
     

    Return Count of Items

    Whenever I use a Filter Query in a Get Items action, I always like to return the count of items returned in a Compose action. This is helpful when building a flow and can also be used to troubleshoot your flow.

    Insert a Compose action. Add an Expression. Use the length() function.

    Select the Dynamic content tab and insert the value dynamic content from the Get Items action into the length() function.

    Run a test. Review the output of the Compose action. If it's not outputting the number of files you are expecting, you'll need to troubleshoot why. One of the reasons could be if you have more than 100 files in your document library. If so, you will need to toggle on Pagination. 

    Apply to Each

    Now you can loop through the files returned from the Get Files (properties only) action. It's always more efficient to loop through files that meet your criteria. If you want to send a message for each file returned, then you would also nest the Post message in a chat or channel action inside the Apply to Each action.

    However, if you want to send a single message with a list of files and the rows, you'll need to have the Post message in a chat or channel OUTSIDE of the Apply to Each action.
     
    To learn more about the Apply to Each action—check out this YT Tutorial:

    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

    List Rows Present in a Table

    From here you will need to use the List Rows Present in a Table action to get each file and return the count of rows in each file. However, you need to ensure the data in your Excel file are contained in a table. 
     
     
    ... more to come but in the meantime you'll want to refer to the YT Tutorials linked below:
     

    In this Microsoft Power Automate tutorial, I’ll show you how to dynamically set the File and Table field.

    IN THIS VIDEO:
    ✓ How to create an Automated Cloud Flow
    ✓ How to dynamically select a Table in the List Rows Present in a Table Action
    ✓ How to use the Parse JSON action
    ✓ How to use the When a file is created (properties only) trigger
    ✓ How to avoid the Apply to Each Action
    ✓ How to Create an Item in SharePoint from Excel Data
     
    ---
     
     
    Formatting Excel data into a table can be done with a few clicks. If you have a workbook with multiple sheets of data all needing to be formatted into a table—it would take too many clicks.
     
    In this video tutorial I will show you how add a script to Excel that will format all of the data in your entire workbook into tables. You can even customize the table style. This time saving automation will allow you to quickly create multiple tables with a single click.
    This tutorial will also cover how to use the Run Script action in a Power Automate flow to completely automate adding Excel data into a SharePoint list. I will show you how to dynamically select an Excel file and table.
     
     
    IN THIS VIDEO:
    ✓ How to Add a Script to Microsoft Excel
    ✓ How to Create Multiple Excel Tables Quickly
    ✓ How to use the Run Script action in Microsoft Power Automate
    ✓ How to import data from Excel into a SharePoint List with a Power Automate Flow
    ✓ How to Use the Get Tables Action
    ✓ How to Use a Dynamic Table Name and File Name in the List Rows Present in a Table Action
    ✓ How to Copy an Power Automate Action and Reuse It
     
     
    Hope this helps!

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 959

#2
Valantis Profile Picture

Valantis 872

#3
Haque Profile Picture

Haque 589

Last 30 days Overall leaderboard