@ProgrammingCoffee Is this a screenshot from your Filter Array action? If so the logic behind this is incorrect.
createArray(outputs('Get_files_(properties_only)')?['LastModified']):
This creates an array of LastModified dates for files retrieved by the Get files (properties only) action. Each file’s LastModified date indicates when it was last modified.
addDays(utcNow(), -730)
This subtracts 730 days (2 years) from the current date/time (utcNow()) to calculate a date in the past. Eg (Output of November 29, 2022, 14:30:00 UTC)
Why the Logic Doesn't Work
Your filter query is using a static function in the value fields. It doesn't reference any items from the array. Your filter should evaluate the items. In your case, since you are looking at the Modified date of the files the Filter Array action isn't necessary (as previously mentioned)/
Instead, you need to use the Filter Query in the Get Files (properties only) action.
Compose the Timestamps
Whenever I work with dates and times I find it easier to place the expression in a Compose action and run tests to ensure the expression is outputting as expected. Tip: Always rename your actions to keep your flow organized. This is especially helpful when you are using more than one instance of the same action.
This can help speed up your flow building process. In your case, use a Compose action and store the following expression:
formatDateTime(addDays(utcNow(), -730), 'yyyy-MM-ddTHH:mm:ssZ')
Run a test. Review the outputs. The output will display a date from two years ago at the exact time you ran the flow (e.g., if you ran it at 3:45 PM, the output will show 3:45 PM two years ago).
However, if your intention is to consider the entire day two years ago (all 24 hours), you’ll need to manually create:
- A start timestamp (12:00 AM) for the beginning of the day.
- An end timestamp (11:59 PM) for the end of the day.
This ensures you include all data for that day, regardless of the time it was modified.
Edit the expression by clicking on it and adjusting the time to 00:00:00 (for 12 AM). Don't forget to press Update to save your changes.
You can hover over the label to ensure that the change has been made.
Duplicate the action by clicking on the three dots and selecting Copy to Clipboard.
Click + Next step. Click on My Clipboard and then click on your copied action to insert it.
Don't forget to rename your action.
Click on the expression to edit it and adjust the time so it's 11:59 PM. Don't forget to press update to save your changes.
Run a test. Review the outputs.
Get Files (Properties Only)
This action returns files and folders. To filter out files only you can use the following filter query:
FSObjType eq 0
You can also add the arguments to check the modified date.
FSObjType eq 0 and LastModified ge '[Compose Start Date]' and LastModified le '[Compose End Date]'
The filter query logic is as follows:
FSObjType eq 0:
Ensures only files are retrieved, excluding folders.
LastModified ge '[Compose Start Date]'
Filters for files modified on or after the start date provided by the Compose action with the Two Year Start Date.
LastModified le '[Compose End Date]'
Filters for files modified on or before the end date provided by the Compose action with the Two Year End Date.
Toggle On Pagination
Additionally, the default limit of files returned by the Get Files (properties only) action is 100. You will need to toggle on pagination. Click on the three dots of the Get Files (properties only) action. Select Settings.
Toggle on pagination and set a threshold. Scroll down and press done. Keep in mind that retrieving a large number of items can slow down your flow significantly. It’s always better to filter results as much as possible to minimize the number of items retrieved.
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.
Condition Check
Add a Condition action to your flow. If items have returned (aka there is number stored in the Compose action—that is not equal to 0), add the rest of your actions to the Yes branch. If not, do nothing.
Hope this helps!