Skip to content

Let's POWER Automate

From no-code to low-code

Menu
  • Expressions
  • Filters
  • General
  • Problems
  • Triggers
  • Application specific solutions
    • Excel
    • Forms
    • Planner
    • Outlook
    • SharePoint
    • Teams
  • Resources
Menu

Power Automate to filter files in SharePoint by file name

Posted on February 14, 2021April 14, 2021 by Tom

“I’m trying to filter files in SharePoint by the file name but Power Automate tells me that column ‘Name’ doesn’t exist.”

“Column ‘Name’ does not exist. It may have been deleted by another user.”


When using ‘Get files’ in Power Automate, you get the file ‘Name’ dynamic content as an output, but that doesn’t mean there’s a column called ‘Name’ you could use in the OData Filter Query. As always, it’s not important how the dynamic content is called, but what is behind. And behind the dynamic content ‘Name’ is a value ‘{Name}’.

Power Automate file name internal name

In many situations that would be the column internal name the Filter Query expects, but not here. You can’t use the ‘{Name}’ in the Filter Query as you’d end up with another error message: The $filter expression “{Name} eq ‘xxxx'” is not valid. Creating query failed. To filter by the file name you need a bit of SharePoint background knowledge.

Document library internal names

SharePoint has a set of hidden internal names used on document libraries. They don’t appear in the file properties so it’s hard to find them, but they’ve been in SharePoint since “ancient” versions. The ones I consider most important for filtering in Power Automate are in the table below.

Internal nameDescriptionExample data
FileLeafRefName of file including extensionExampleFile.docx
FileRefServer relative URL path of the filesites/Playground/Shared Documents/20201231/ExampleFile.docx
File_x0020_TypeFile typedocx

Use FileLeafRef instead of Name

As you can see in the table above, file name including extension is hidden behind ‘FileLeafRef’ column. If you use that column in the OData Filter Query you’ll get the file you’re looking for.

FileLeafRef eq 'FileNameWithExtension'

Note: don’t forget the single quotes around the file name. It doesn’t matter if you use dynamic content or typed-in value, it’s needed in both cases.

The example ‘Get files’ action on the screenshot above will return only file test.csv (if it exists). You can use the same column, only with different operator, also to find files with a string in the file name.

Summary

Filtering files from a document library is a rare situation when Power Automate won’t give you a hint. In most situations you can find the internal name in the list/library settings or in the action output. Not so with the default columns in a document libraries. Unless you know the columns internal names, you won’t be able to use the OData Filter Query.

I believe it’s worth filtering directly in the ‘Get files’ action whenever possible, and the 3 internal names from this article should give you all you need.

It is not the only way to find a file, there’s also a solid workaround to get all files and then filter using ‘Filter Query’ action. But then you must get back the dynamic content after the filtering and I prefer to keep my flows simple.


Do you struggle with the various expressions, conditions, filters, or HTTP requests available in Power Automate?

I send one email per week with a summary of the new solutions, designed to help even non IT people to automate some of their repetitive tasks.

All subscribers have also access to resources like a SharePoint Filter Query cheat sheet or Date expressions cheat sheet.

Zero spam, unsubscribe anytime.

4 thoughts on “Power Automate to filter files in SharePoint by file name”

  1. Juan Marcial says:
    November 12, 2021 at 11:34 am

    All of the sudden my query using FileLeafRef does not work correct. After some digging I found out that new files are not found with the condition I set while old fields do. Maybe Microsoft changed the use of this property? Any help would be appreciated.

    Reply
  2. Juan Marcial says:
    November 12, 2021 at 11:41 am

    I think I found the problem. The library has more than 5000 files and it seems SharePoint only consider for the query the first 5000 files !!!!!!! Incredible!!!! I guess I have to find another way to search for the files in a library 🙁

    Reply
    1. Jirka says:
      May 3, 2022 at 11:44 am

      Hi Juan, I know it’s long time ago 😉

      Have you found the solution how to deal with 5000 files limit?

      Have you tried to change Pagination and Treshold in Settings?

      thanks, have a nice day 🙂

      Reply
  3. Jirka says:
    May 3, 2022 at 11:40 am

    Hey Tom, your blog is just great! I’m happy I’ve found it 🙂

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Now available:

The Ultimate Power Automate expressions cheat sheet
Equip yourself with the tool to translate your thoughts into Power Automate expressions!

Do you struggle with the various expressions, conditions, filters, or HTTP requests available in Power Automate?

I send one email per week with a summary of the new solutions, designed to help even non IT people to automate some of their repetitive tasks.

All subscribers have also access to resources like a SharePoint Filter Query cheat sheet or Date expressions cheat sheet.

Zero spam, unsubscribe anytime.

Hello and welcome!

My name is Tom and I'm a business process automation consultant and Microsoft MVP living in the Czech Republic. I’ve been working with Microsoft technologies for almost 10 years, currently using mainly Power Automate, SharePoint, Teams, and the other M365 tools.

I believe that everyone can automate part of their work with the Power Automate platform. You can achieve a lot by "clicking" the flows in the designer, but you can achieve much more if you add a bit of coding knowledge. And that's what this blog is about.

To make the step from no-code Power Automate flows to low-code flows: using basic coding knowledge to build more complex yet more efficient flows to automate more of your daily tasks.

  • Format results of date calculation in SharePoint columnJune 29, 2022
  • Why is your Power Automate flow creating duplicatesJune 26, 2022
  • How to create a unique identifier in your Power Automate flowJune 22, 2022
  • How to assign custom SharePoint permission level with Power AutomateJune 19, 2022
  • Remove permissions from a specific SharePoint user with Power AutomateJune 15, 2022

Power Automate blogs worth visiting

Damien Bird
Dennis (Expiscornovus)
Paul Murana

© 2022 Let's POWER Automate | Powered by Superbs Personal Blog theme