“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}’.
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 name | Description | Example data |
---|---|---|
FileLeafRef | Name of file including extension | ExampleFile.docx |
FileRef | Server relative URL path of the file | sites/Playground/Shared Documents/20201231/ExampleFile.docx |
File_x0020_Type | File type | docx |
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.
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.
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 🙁
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 🙂
thanks, very helpful info! btw as a solution we just moved some of the files into another library. and included Order By Modified desc in our case it could work because we are checking only latest files.
Hey Tom, your blog is just great! I’m happy I’ve found it 🙂
This blog is a life-saver! Can’t thank you enough for breaking this all down for me.