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 / Condition running in loop
Power Automate
Answered

Condition running in loop

(0) ShareShare
ReportReport
Posted on by 319

Hello,

 

I have an issue that the condition in the screenshot below runs for each iterations. I am here trying to look for the expiry date of the documents in the document library and the triggering an email wherein the expiry date is 30 days ahead from today's date.

 

There is only one document which is identified to have a expiry date 30 days from now but the email is triggered for all apply to each iterations. How can I get this resolved ? I can't even bring the condition out of the apply to each as it dependent on output within the apply to each.

 

Prathameshpatka_0-1695052570346.png

 

Categories:
I have the same question (0)
  • efialttes Profile Picture
    14,756 on at

    Hi @Prathameshpatka !
    Can you share more information about the inpus for both 'apply to each' action blocks. Just hover your mouse over the input values and share the WDL expression displayed
    Also please expand the Condition action block and share the condition rule you are evaluating inside
    The more information context, the faster you will get a useful insight

    THanx!

  • Prathameshpatka Profile Picture
    319 on at

    Hi @efialttes 

     

    Here are the screenshots as requested :

     

    Prathameshpatka_0-1695053218812.pngPrathameshpatka_1-1695053247684.pngPrathameshpatka_2-1695053276297.pngPrathameshpatka_3-1695053302546.pngPrathameshpatka_4-1695053334999.png

     

  • efialttes Profile Picture
    14,756 on at

    Oops! I probably did not explain myself properly. I was suggesting to share the inputs used for both 'Apply to each' action blocks, both of them are displayed with the text 'value' so it looks like you have nested two 'Apply to each' with the same input even though you only need one, but just to make sure...
    Thanx!

    efialttes_0-1695053627121.png

     

  • efialttes Profile Picture
    14,756 on at

    Hi again!
    Also, it seems you have defined a custom column on your Sharepoint Library called 'Expiry date', right? If so, is it defined of type Single Line of Text, or DateTime, or...?
    Thanx!

  • Prathameshpatka Profile Picture
    319 on at

    Hi @efialttes 

     

    I have removed one of the apply to each and that has only sent me one email as it should but the flow looks to have failed for next iteration as the expiry date was null ? Yes and the expiry date column is custom which is set to date and time type.

     

    Prathameshpatka_0-1695054246594.png

     

  • efialttes Profile Picture
    14,756 on at

    Hi again!
    so we are closer to a happy ending, right?
    As you suspect, the expression you are using...

     

     

     

    formatDateTime(outputs('Expiry_date'),'yyyy-MM-dd')

     

     

     

    ...will fail if the input value is null / empty,
    So there are two options:
    -in your SP library, declare custom column as mandatory, so all items will have an Expiry_date value, or
    -implement a workaround in your flow, for example use this expression instead:

     

     

     

    formatDateTime(coalesce(outputs('Expiry_date'),'1999-12-31T00:00:00Z'),'yyyy-MM-dd')

     

     


    ...so if Expiry date is null, it will be replaced and transformed into 1999-12-31

    Hope this helps
    ==========

  • Verified answer
    Prathameshpatka Profile Picture
    319 on at

    Hi @efialttes ,

     

    I have handled the Null condition in the flow and that seems to have helped as previously it failed when there was no expiry date found. It is now sending me separate emails for the docs which have an expiry date after 30 days. I will do some more testing and then come back with a final update.

     

    Prathameshpatka_0-1695199665217.png

     

  • efialttes Profile Picture
    14,756 on at

    @Prathameshpatka 
    Sounds promising! THe approach you chose (use a condition action block) is simpler than the one I suggested, and perfectly valid specially if your SP library does not have a huge nr of files stored.
    Please let us know your progress, and do not forget to mark this topic as "Solved" by clicking "Accept as a solution" if your problem is finally solved!

    THis way others with the same problem can find a solution faster. Please also note you can even select several responses as solution, even from different community members!

     

    Flow_AcceptSolution.png

     
     

    Thanx for your help making this community great!



    ========================================================================

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
David_MA Profile Picture

David_MA 124 Super User 2026 Season 1

#2
Ellis Karim Profile Picture

Ellis Karim 52 Super User 2026 Season 1

#3
Haque Profile Picture

Haque 50

Last 30 days Overall leaderboard