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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / SharePoint Get Items o...
Power Automate
Unanswered

SharePoint Get Items oData filter not returning expected results with AND/OR condition

(0) ShareShare
ReportReport
Posted on by 10

I am reading in data from a sharepoint list and I need to filter the data on 3 criteria:

1. Draft is false, AND

2. Date Posted is greater than or equal to today - 7 days, OR

3. Due Date is less than or equal to today + 14 days.

 

Conditions 2 and 3 are nested - so the primary criteria is Draft is equal to false. Then, if the item meets criteria 2 OR 3, then it should be returned. When I test each condition independently, or use "and" for all three criteria, it works fine. 

 

When I use a formula expression to determine the ranges:

(Draft eq 'false') and ((Date_x0020_Posted ge '@{addDays(utcNow('yyyy-MM-dd'), -7)}') or (Due_x0020_Date le '@{addDays(utcNow('yyyy-MM-dd'), 14)}'))

 

This is what is shown in the test input results, which looks correct to me:

(Draft eq 'false') and ((Date_x0020_Posted ge '2024-01-15T00:00:00.0000000') or (Due_x0020_Date le '2024-02-05T00:00:00.0000000'))

 

I also tried using functions to generate the target dates and use those outputs as variables in the odata filter (these outputs are formatted as 'yyyy-MM-dd'):

(Draft eq 'false') and ((Date_x0020_Posted ge '@{outputs('FormatPost7')}') or (Due_x0020_Date le '@{outputs('FormatDue14')}'))

 

Testing yields this expression, which again looks correct to me:

(Draft eq 'false') and ((Date_x0020_Posted ge '2024-01-15') or (Due_x0020_Date le '2024-02-05'))

 

However, I have rows of data being returned that do NOT meet the criteria as written. 

 

I have tried all of the following:

  1. Using 'gt' and 'lt' instead of 'ge' and 'le' - same incorrect results
  2. Removing the 'yyyy-MM-dd' format from the UTCnow piece of the expression to get the date
  3. Using data functions to reformat the date (i.e. derive the target dates and using those outputs as dynamic variables in the expression)
  4. Using data functions to convert UTC to my time zone, and then do reformatting of the dates
  5. Trying various different date formatting both in the expression as well as in the formats for variables
  6. Hardcoding the dates (rather than using an expression - not what is needed, but tried it to see if anything would change)

Any help would be appreciated! I have spent hours trying to figure this out and I can't figure out why this isn't working as I'd expect.

 

My testing yields incorrect results, with records that should fail the nested OR criteria being present in the output:

 

DraftDue DateDate PostedResult
False2023-12-312023-11-29Should FAIL, but shows up
False2024-01-052023-11-03Should FAIL, but shows up
False2024-01-312024-01-08PASS - shows up
False2024-02-292024-01-22PASS - shows up
True2024-01-312024-01-20PASS - not returned
True2023-11-292023-10-15

PASS - not returned

Categories:
I have the same question (0)
  • ManishSolanki Profile Picture
    15,091 Super User 2025 Season 2 on at

    Hi @1AMJED1 

     

    Pls try the below filter query:

    (Draft eq '@{false}') and ((Date_x0020_Posted ge '@{addDays(utcNow('yyyy-MM-dd'), -7)}') or (Due_x0020_Date le '@{addDays(utcNow('yyyy-MM-dd'), 14)}'))

     

    If this helps & solves your problem, please remember to give a 👍 and accept my solution as it will help others in the future.

     

  • Verified answer
    1AMJED1 Profile Picture
    10 on at

    Hi @ManishSolanki thanks for the reply! After a good night's sleep and reviewing your suggestion very closely, I realized that this is 100% a me problem and that I need to rework the logic. 

     

    The first and second criteria are fine. The third criteria (Due Date in the next 14 days) is missing an AND criteria that it must be greater than today AND in the next 14 days. The original logic was picking up unwanted rows because the due date was less than today + 14 days (which is true for things that were due in the past). 

     

    My revised formula is now: (Draft eq '@{false}') and ((Date_x0020_Posted ge '@{addDays(utcNow('yyyy-MM-dd'), -7)}') or ((Due_x0020_Date le '@{addDays(utcNow('yyyy-MM-dd'), 14)}') and (Due_x0020_Date ge '@{utcNow('yyyy-MM-dd')}')))

     

    May the Force be with you!

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 522 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 364 Moderator

#3
abm abm Profile Picture

abm abm 243 Most Valuable Professional

Last 30 days Overall leaderboard