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 / Loop Condition on Date
Power Automate
Answered

Loop Condition on Date

(0) ShareShare
ReportReport
Posted on by 20

I have a For Loop and this date, if the next date in the for loop is August I want to hit the back arrow, if it is December I want to hit the forward arrow 3 times for example. I can create a column in Excel with the month of each date in number format. How can I implement this logic in the Loop Condition

 

FlashDota_0-1699039592825.png

 

I have the same question (0)
  • Verified answer
    MichaelAnnis Profile Picture
    5,727 Moderator on at

    I assume you already know how to Extract the text from that element displayed in your screenshot, so I'm continuing from there.

    This process will evaluate the 2 each time and only click the arrow once upon each valuation, then re-evaluate.  That way it's > or < 0, not extra lines of code trying to decipher if the 2 are part of the same year or not.

     

    Let's say that variable is %ElementText% and your next Loop date is a date variable set to %NextLoopDate%.

    Also %NextLoopDate% should be on the 1st of the month in this case, if not, convert %NextLoopDate% to Month/01/Year so it can be compared equally against %ElementDate%

     

    Label Click Arrows
        Convert Text to Datetime %ElementText% custom format MMMM yyyy to %ElementDate%

        If %NextLoopDate% > %ElementDate%

            'click right arrow

            GoTo Label Click Arrows  'this will basically loop us until %NextLoopDate% = %ElementDate%

        Else(IF) %NextLoopDate% < %ElementDate%

            'click left arrow

            GoTo Label Click Arrows  'this will basically loop us until %NextLoopDate% = %ElementDate%

        End(IF)

     

    Good luck

     

  • Verified answer
    Agnius Bartninkas Profile Picture
    Most Valuable Professional on at

    I personally prefer not using labels, so my take on this would be more like this:

     

    Loop While %NextLoopDate% <> %ElementDate%

        Convert Text to Datetime %ElementText% custom format MMMM yyyy to %ElementDate%

        If %NextLoopDate% > %ElementDate%

            'click right arrow

        Else(IF) %NextLoopDate% < %ElementDate%

            'click left arrow

        End(IF)

    End (loop)

     

    But otherwise your solution does the trick!

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

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
David_MA Profile Picture

David_MA 261 Super User 2026 Season 1

#2
11manish Profile Picture

11manish 185

#3
Haque Profile Picture

Haque 168

Last 30 days Overall leaderboard