Skip to main content

Notifications

Power Automate - Building Flows
Answered

Condition returning false when it should be true

Posted on by 297
Hello,
 
Hoping for some advice on a flow I'm working on that I just can't seem to get working... hopefully it's something easy that I'm missing or someone can explain why it won't work.
 
I have a condition that is essentially just checking if a date is equal to another date - I know for fact that one of the dates DOES equal the other date but it continues to result in false in the condition. 
 
My first apply to each is checking if any of the items have a contract end date that is coming up in the next 14 days. I then use a compose action to store those dates.
 
 
Then, I introduce a 2 minute delay, and in that time i change one of the dates so that it is no longer within the two week period, but one still is. 
 
My condition is then checking, does any of the dates stored in the compose equal to any of the dates stored from the 'get items 3', which as mentioned above will now have one date that still meets the above condition, and one that doesn't. 
 
However the 'condition 3' is passing them both as false, when in fact one of them should still be true as the date has not changed.
 
 
Does anyone know what could be wrong with the 'Condition 3' or how I have setup the flow to work?
 
 
Here are some screenshots from a flow run that should the outputs.
  
 
 
Any help appreciated!
 
 
  • Suggested answer
    rzaneti Profile Picture
    rzaneti 3,183 on at
    Condition returning false when it should be true
    Hi @Jap11,

    The step-by-step below is oversimplified and is focused in how to compare the dates at the same position in different arrays. If you need some additional support to adequate it to your use case, let me know!
     
    Knowledge base
    Before we get started, I will share the link for some blog posts that I wrote about the topics discussed here. It can be useful for you or for any other user that finds this thread in the future.
    - How to work with Power Automate expressions: http://digitalmill.net/2024/02/27/writing-expressions-in-power-automate/

    Lists and solution Overview 
    For this example, we will use two different SharePoint Lists, Date A and Date B:


    In the flow, we will access the records from List B, loop them and have a condition to test if the Title property is divisible by 2. If it is, we will then store it in a separated array, created as a variable during the flow. After that, we will compare the dates from List A with those at the same position in the dates array. 

    Flow initial setup
    Let's start by retrieving the records from both Lists with 2 Get Items actions (you already did it, based on the images shared before):


    Right after that, we need to initialize two variables: one for storing the index counter, which must have an integer data type an initial value of 0 (make sure to type the zero, you must not leave the value empty); and other for the list of the dates captured from List B, which must have an array data type and no initial value:


    Looping List B
    Now let's loop the List B records using an Apply to each. To keep your flow more readable, I recommend you to rename the Loop to include the List name (highlighted in yellow). Inside the loop, we have a condition that is testing if the Title value is a multiple of 2 (for that, I'm using the expression mod(int(item()['Title']), 2) and testing if this is equal to zero). For your case, you can use any condition that makes more sense. Since we want to keep only the dates from records which Title is a multiple of 2, add an Append to array variable to the If yes block, set the "name" as the array variable created earlier and set its value as the date dynamic content from the List B:  


    At this point, you will have an array containing only the dates from records that match the condition, which in our example are Nov 13, Nov 19 and Nov 16, in this same order. 

    Looping List A
    Now we can loop the List A, as you already did in your flow. Inside the loop, let's have a condition for testing if the date from List A record matches the date from array at the same position. It means that the first SP List record's date will be compared with the date in the first array element, the second record's date with the date in the second array element, and so on. As you already did from your end, we need to format both dates, and for this example we are using the 'yyyy-MM-dd' format, which will result in the expression of formatDateTime(items('Apply_to_each_-_A')?['date'], 'yyyy-MM-dd') for the SP List date. 

    We will use the counter variable to access the correct array element. To reference the array's element of the current counter position, we use the expression formatDateTime(variables('dates')[variables('counter')], 'yyyy-MM-dd'). Inside the If yes and If no blocks, you can allocate the actions that must be executed in each scenario:


    As the counter is set as 0, when the loop run its first iteration, the first array element will be accessed, since the position counting starts at zero. However, for each loop iteration we need to increment this counter, so it will values 1 for the second SP List element, 2 for the third, and so on. So we need to change the counter variable value for each loop iteration. 

    After your condition but still inside the loop, add a Increment variable action, setting counter as name and 1 as value. It will ensure that after performing the actions within the condition, your variable value will be incremented by 1:


    Testing the flow
    Now we are good to go. The List A dates are Nov 13, Nov 15 and Nov 16, while the array dates are Nov 13, Nov 19 and Nov 16. It means that, when running the Apply to each - A, our condition must return true only for the first and third iterations, and false for the second one.

    After running the flow, this is the outcome for the first iteration (true):


    Second iteration (false)


    Third iteration (true)


    Let me know if it works for you or if you need any additional help!
    -------------------------------------------------------------------------
    If this is the answer for your question, please mark the post as Solved.
    If this answer helps you in any way, please give it a like.
    http://digitalmill.net/
    https://www.linkedin.com/in/raphael-haus-zaneti/
  • Jap11 Profile Picture
    Jap11 297 on at
    Condition returning false when it should be true
    Hello @rzaneti - I think what you're suggesting is what I need - so if you're able share a step by step that would be greatly appreciated!
     
    To confirm I need a way to store the Contract end Dates from Apply to Each.
     
    I then need a condition to check if any of those dates match those in Apply to Each 3.
     
    If that is true, and any of the dates from Apply to Each and Apply to Each 3 sync up then it should send an email.
     
    Thanks again,
    Josh
     
     
  • Verified answer
    rzaneti Profile Picture
    rzaneti 3,183 on at
    Condition returning false when it should be true
    Hi @Jap11,
     
    It looks like your two Apply to each are not nested, right? If this is the case, Power Automate will have trouble to capture the date from a specific array element looped in a different Apply to each. It would also explain why can't you see the Compose outputs in the dynamic contents from within the other Apply to each.
     
    Are you trying to compare items within the same position in the different loops? For example, if you are currently accessing the 3rd array element in Apply to each 3, would you like to compare its date exclusively with the 3rd element of the other Apply to each? If this is the case, you can use a variable to control the current array iteration index and then access the "n" element in the body/value output from the Get items looped in Apply to each, and then its date property. Please clarify it this is what you need and I will be back with a quick step-by-step on how to setup this strategy :)
     
    Let me know if it works for you or if you need any additional help!
    -------------------------------------------------------------------------
    If this is the answer for your question, please mark the post as Solved.
    If this answer helps you in any way, please give it a like.
     
  • Jap11 Profile Picture
    Jap11 297 on at
    Condition returning false when it should be true
    Not sure if this is a bug - but I have just spotted that when I remove my compose from the condition, it does not let me re-add it...
     
    I'm guessing maybe it is not possible to use this here, therefore the condition is returning 'null' opposed to the dates?
     
    If that is the case - does anyone know how I can do this a different way?
     
     

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

November 2024 Newsletter…

November 2024 Community Newsletter…

Community Update Oct 28…

Power Platform Community Update…

Tuesday Tip #7 Community Profile Tips…

Welcome to a brand new series, Tuesday Tips…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 143,246

#2
RandyHayes Profile Picture

RandyHayes 76,308

#3
Pstork1 Profile Picture

Pstork1 63,884

Leaderboard