Skip to main content
Community site session details

Community site session details

Session Id : Rrg3v7QxJopuA9Bu9JtnGd
Power Automate - Building Flows
Answered

Compare if two arrays have the same value

Like (0) ShareShare
ReportReport
Posted on 13 Jun 2024 15:34:41 by 127

Hello Super Community!

 

I gave up on this concept a week ago, then saw a video where the guy did this in 4 minutes https://youtu.be/SFlj1ykpvgM?si=aBUO60wiYcHu44Qz  😕 I tried it with my own data and two hours later...nope!

 

Initialized Variable:  name: First Array, Type: Array

 

[
  {
    "Date array""2024-06-01"
  },
  {
    "Date array""2024-06-02"
  },
  {
    "Date array""2024-06-03"
  },
  {
    "Date array""2024-06-04"
  },
  {
    "Date array""2024-06-05"
  },
  {
    "Date array""2024-06-06"
  },
  {
    "Date array""2024-06-07"
  },
  {
    "Date array""2024-06-08"
  },
  {
    "Date array""2024-06-09"
  },
  {
    "Date array""2024-06-10"
  },
  {
    "Date array""2024-06-11"
  },
  {
    "Date array""2024-06-12"
  }
]
 
Initialized Variable:  name: Second Array, Type: Array
 
[
{
"Date array": "2024-06-06",
"List ID": 11
},
{
"Date array": "2024-06-07",
"List ID": 11
}
]
 
Condition: 
Select an output... 
variables('First Array')
 
variables('Second Array') contains item()
 
 
Condition statement I'm trying to write: if any dates in the Second Array match dates in the First Array, result is TRUE, if not FALSE
Problem: I can't get true results. 
 
Thanks in advance!
 
  • Dianez Profile Picture
    127 on 14 Jun 2024 at 16:19:33
    Re: Compare if two arrays have the same value

    Thank you so much!!!!

  • Verified answer
    Chriddle Profile Picture
    7,932 Super User 2025 Season 2 on 14 Jun 2024 at 07:15:36
    Re: Compare if two arrays have the same value

    Chriddle_0-1718349099638.png

    Filter array filters the output of the flow above for items that are in the first array.

     

    Select 3 collects all their List IDs

    Map: @item()['Item']['List ID']

     

    Chriddle_1-1718349325852.png

     

  • Dianez Profile Picture
    127 on 13 Jun 2024 at 18:25:05
    Re: Compare if two arrays have the same value

    0_0 wow this is such an eloquent solution without using 3 Apply to each's. This work wayyyy better.  Can I ask you a favor? How do you get the List ID value by itself. I was able to get the "11" with a lot of effort, but perhaps you know a better way? 

     

    item()?['Item/List_ID']  doesn't work. And neither did, item()?['Item']['List_ID']

     

    In any case, thank you so much!

  • Verified answer
    Chriddle Profile Picture
    7,932 Super User 2025 Season 2 on 13 Jun 2024 at 17:17:43
    Re: Compare if two arrays have the same value

    That's no problem:

    Chriddle_2-1718298712148.png

     

    Select

    From: @{outputs('Compose_2')}

    CompareItem: @JSON(concat('{"Date array": "', item()['Date array'], '"}'))

    Item: @item()

     

    Select 2

    From: @{body('Select')}

    Map: @addProperty(item(), 'isInFirstArray', contains(outputs('Compose'), item()['CompareItem']))

     

    Chriddle_3-1718298988461.png

     

    All items in the resulting array have a property "Item" that contains the original item.

  • Dianez Profile Picture
    127 on 13 Jun 2024 at 16:31:24
    Re: Compare if two arrays have the same value

    So, here's the rub. I have to leave the data as-is in the second array. These two arrays are outputs from the original flow, which is much more difficult. After 4 days, I gave up because this was the part that wasn't working. Every single error imaginable came up. There wasn't just one error.

     

    I'll need the "List ID" ( number 11) later on in the flow to update a column in SharePoint.

  • Chriddle Profile Picture
    7,932 Super User 2025 Season 2 on 13 Jun 2024 at 16:13:09
    Re: Compare if two arrays have the same value

    If you need true/false per item, replace Compose 3 with the following Select:

    Chriddle_0-1718295058101.png

    From: @{body('Select')}

    Map:  @addProperty(item(), 'isInFirstArray', contains(outputs('Compose'), item()))

    Chriddle_1-1718295182886.png

     

  • Chriddle Profile Picture
    7,932 Super User 2025 Season 2 on 13 Jun 2024 at 15:59:46
    Re: Compare if two arrays have the same value

    Challenge accepted, 2 minutes 😀

    Chriddle_0-1718294205022.png

    Compose contains your First array

    Compose 2 contains your Second array

     

    Select

    From: @{outputs('Compose_2')}

    Date array: @{outputs('Compose_2')}

     

    Compose 3

    @{equals(intersection(outputs('Compose'), body('Select')), body('Select'))}

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

Announcing our 2025 Season 2 Super Users!

A new season of Super Users has arrived, and we are so grateful for…

Paul Stork – Community Spotlight

We are honored to recognize Paul Stork as our July 2025 Community…

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Loading complete