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 stuck subtracting...
Power Automate
Answered

Loop stuck subtracting days

(0) ShareShare
ReportReport
Posted on by

I'm trying to modify steps that work well in another flow, that loops through adding days until I get to the next Sunday (for example).

In the new instance I'm trying to use the loop to subtract one day until it finds the most recent Monday (see screenshot below). When the flow runs, it is stuck in this loop. Not sure what I'm doing wrong, aside from changing Sunday to Monday, and making it a negative 1 instead of positive, everything else is identical to the working steps. Thanks for any insights.snip1.PNG

I have the same question (0)
  • Murphys110 Profile Picture
    on at

    I think I know what I did... the 'store the result into' should "CurrentDateTime" or it's always starting from today.... will test and update here.

     

  • eetuRobo Profile Picture
    4,549 Super User 2026 Season 1 on at

    Your %Monday% -variable is dateTime format and not weekdays. So it never is actually 'Monday' but a date like 28/02/2024 7:00:00PM.
    Use DayOfWeek function on that too.
    eetuRobo_2-1709225846248.png
    And to make the loop go backwards add %LoopIndex% variable that you decrease every loop and use that in the add time Add -field

    eetuRobo_3-1709225927912.png

     

    You can copy paste this code to your PAD if you want:

    SET LoopIndex TO 0
    DateTime.GetCurrentDateTime.Local DateTimeFormat: DateTime.DateTimeFormat.DateAndTime CurrentDateTime=> CurrentDateTime
    LOOP WHILE (CurrentDateTime.DayOfWeek) <> ($'''Monday''')
    DateTime.Add DateTime: CurrentDateTime TimeToAdd: LoopIndex TimeUnit: DateTime.TimeUnit.Days ResultedDate=> CurrentDateTime
    SET Monday TO CurrentDateTime.DayOfWeek
    Variables.DecreaseVariable Value: LoopIndex DecrementValue: 1
    END

     

     

     

     

  • Verified answer
    Murphys110 Profile Picture
    on at

    That did it... 🙂 Pasting screenshot of the very simple fix... feeling like Homer Simpson... d'oh!

    snip2.PNG

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 Launch!

Jump in, show your community spirit, and win prizes!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
Valantis Profile Picture

Valantis 411

#2
David_MA Profile Picture

David_MA 300 Super User 2026 Season 1

#3
Vish WR Profile Picture

Vish WR 291

Last 30 days Overall leaderboard