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 / Power Automate Filter ...
Power Automate
Answered

Power Automate Filter Querry to search ge'today and le'30 days but to not look on the year

(0) ShareShare
ReportReport
Posted on by 21

Hi guys, 

I have a filter query: (Date ge 'convertFromUtc(utcnow(),'Eastern Standard Time','yyyy-MM-dd')') and (Date le 'addDays(convertFromUtc(utcNow(),'Eastern Standard Time','yyyy-MM-dd'),30,'yyyy-MM-dd')') is working. Still, I need not to include the year. For example now this filter includes in the output the date 01/08/2023 but I want also to be included 01/08/2012 for example.

 

Any ideas? 
Thx in advance!

 

Categories:
I have the same question (0)
  • SamLed Profile Picture
    2,338 Moderator on at

    Hi Claudiu1,

     

    The trick is to format both Date and utcNow() to 'MM-dd'.

     

    But you can't format date within Get Items query filter as date value will be get at query run time while power automate expression are evaluated before action runs the query. 

     

    So you have to use a Filter Array action with "value" dynamic content from Get Items as input. Then filter according to your need.

     

    Here a small flow to illustrate, it gets items from a list then filter result having items Created 2 or 4 month later from now (October and December) :

     

     My formula is : @Anonymous(equals(formatDateTime(item()?['Created'], 'MM'), addToTime(utcNow(), 2, 'Month', 'MM')),equals(formatDateTime(item()?['Created'], 'MM'), addToTime(utcNow(), 4, 'Month', 'MM')))

     

    As formula is a complex one you'll have to enter advanced mode edition of the action :

    SamLed_1-1690890173032.png

    You get this :

    SamLed_2-1690890246497.png

    Replace empty equals formula proposed by yours :

    SamLed_3-1690890321587.png

     

    Filter array now returns only items created on October or December regardless of the day or year.

     

    Your query should look like this : @And(greaterOrEquals(formatDateTime(item()?['Date'], 'MM'), convertFromUtc(utcnow(),'Eastern Standard Time','MM-dd')), lessOrEquals(formatDateTime(item()?['Date'], 'MM'), addDays(convertFromUtc(utcNow(),'Eastern Standard Time','yyyy-MM-dd'),30,'MM-dd')))

     

    Where 'Date' is the internal name of the field on which you want to test the date.

    ______________________________________________________________

    If I have answered your question, please Accept the post as solution.
    If you like my response, please Thumbs Up.

     

  • Claudiu1 Profile Picture
    21 on at

    The execution of template action 'Filter_array' failed: The evaluation of 'query' action 'where' expression '@And(greaterOrEquals(formatDateTime(item()?['StartDateInCareer'], 'MM'), convertFromUtc(utcnow(),'Eastern Standard Time','MM-dd')), lessOrEquals(formatDateTime(item()?['StartDateInCareer'], 'MM'), addDays(convertFromUtc(utcNow(),'Eastern Standard Time','yyyy-MM-dd'),30,'MM-dd')))' failed: 'The template language function 'formatDateTime' expects its first parameter to be of type string. The provided value is of type 'Null'. Please see https://aka.ms/logicexpressions#formatdatetime for usage details.'.

  • SamLed Profile Picture
    2,338 Moderator on at

    Have you got empty 'StartDateInCareer' in your list ?

  • Claudiu1 Profile Picture
    21 on at

    Unfortunately yes

  • Verified answer
    SamLed Profile Picture
    2,338 Moderator on at

    Try this one : 

     

    @if(empty(item()?['StartDateInCareer']), false, and(greaterOrEquals(formatDateTime(item()?['StartDateInCareer'], 'MM'), convertFromUtc(utcnow(),'Eastern Standard Time','MM-dd')), lessOrEquals(formatDateTime(item()?['StartDateInCareer'], 'MM'), addDays(convertFromUtc(utcNow(),'Eastern Standard Time','yyyy-MM-dd'),30,'MM-dd'))))

    ______________________________________________________________

    If I have answered your question, please Accept the post as solution.
    If you like my response, please Thumbs Up.

  • Claudiu1 Profile Picture
    21 on at

    Worked! Thank you a lot!

  • Claudiu1 Profile Picture
    21 on at

    Hello again, 

    I misinterpreted the results. Now it exports everything correctly, but from the following month 09 and does not take into account the current month. I would like to export everything from the current month 08 so that I can run it monthly at the beginning of the month

  • SamLed Profile Picture
    2,338 Moderator on at

    I just figured out you had messed up the DateTime format ('MM' instead of 'MM-dd') and I didn't pay attention to it when I added empty() function to expression.

     

    Try this :

    @if(empty(item()?['StartDateInCareer']), false, and(greaterOrEquals(formatDateTime(item()?['StartDateInCareer'], 'MM-dd'), convertFromUtc(utcnow(),'Eastern Standard Time','MM-dd')), lessOrEquals(formatDateTime(item()?['StartDateInCareer'], 'MM-dd'), addDays(convertFromUtc(utcNow(),'Eastern Standard Time','yyyy-MM-dd'),30,'MM-dd'))))

    ______________________________________________________________

    If I have answered your question, please Accept the post as solution.
    If you like my response, please Thumbs Up.

  • Claudiu1 Profile Picture
    21 on at

    Don't know why but know is exporting only the infos from 09-01 

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!

Leaderboard > Power Automate

#1
Haque Profile Picture

Haque 283

#2
David_MA Profile Picture

David_MA 256 Super User 2026 Season 1

#3
Expiscornovus Profile Picture

Expiscornovus 225 Most Valuable Professional

Last 30 days Overall leaderboard