cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
csommerfield
Helper I
Helper I

Compare two objects within a single array or compare a single SP list item to every other item in the same list but itself

I've done this before with other workflow tools but I can't seem to figure it out with flow. 

 

I have a list of items in a single SP list.

 

Fields that I'm querying from each(all) item(s) are:

  • Location
  • Start Date
  • End Date

 

I need to compare a single item to the rest of the items that query. First, make sure their locations are equal. Then I need to see if their date range Start Date to End Date overlapped with each other at all. If the item does overlap, write back to the list item and flag a field IsOverlapped to Yes.

 

To accomplish this with the other workflow tool. I query the SharePoint list and get all items. I then run a for each item returned from query get fields listed above. Then within that same for each, I run another for each that compares the index number of the previous collection and adds to the index of +1. This is so the item isn't compared to itself. I then get the fields from that new collection and run conditions that compare the single selected field from each of the collections. 

 

  • Is location the same? No, skip. If Yes
    • Is that start date of item1 >= start date of item2 && Start date of item2 <= End Date item1 - If yes mark overlap, if not
      • Is EndDate2>= StartDate1 && EndDate2 <= EndDate1 - if yes, mark overlap, if no
        • Is StartDate2 <= StartDate1 && EndDate2 >=EndDate1 - if yes, mark overlap, if no mark no overlap.

 

Trouble I'm having is I'm assuming I use Select and build an array. But I need the index of that array and I need a way to change the index +1 on each run through. As well as comparing the dates and location of 1 item to all items for each item. Any direction would be awesome. Thank you

1 ACCEPTED SOLUTION

Accepted Solutions
abm
Super User
Super User

Hi @csommerfield 

 

You can access the list items by index. Hopefully the below steps will give you an idea how to achieve your requirement.

 

image.png

 

Above compose expression is as follows:

length(body('Get_items')?['value'])
 
Next construct the loop to iterate by index
 
image.png

 

Below are the compose expressions I have used for the above:

 

sub(outputs('Compose'), 1)
body('Get_items')?['value']?[variables('Index')]?['ID']
 

Thanks



Did I answer your question? Mark my post as a solution!

If you liked my response, please consider giving it a thumbs up


Proud to be a Flownaut!

Learn more from my blogPower Automate Video Tutorials

View solution in original post

2 REPLIES 2
abm
Super User
Super User

Hi @csommerfield 

 

You can access the list items by index. Hopefully the below steps will give you an idea how to achieve your requirement.

 

image.png

 

Above compose expression is as follows:

length(body('Get_items')?['value'])
 
Next construct the loop to iterate by index
 
image.png

 

Below are the compose expressions I have used for the above:

 

sub(outputs('Compose'), 1)
body('Get_items')?['value']?[variables('Index')]?['ID']
 

Thanks



Did I answer your question? Mark my post as a solution!

If you liked my response, please consider giving it a thumbs up


Proud to be a Flownaut!

Learn more from my blogPower Automate Video Tutorials

View solution in original post

@abm Thank you that got me started. I'll figure out the rest of the logic

Helpful resources

Announcements
MPA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Welcome Super Users.jpg

Super User Season 2

Congratulations, the new Super User Season 2 for 2021 has started!

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Users online (1,475)