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

SharePoint Array - parsing out unique categories, and finding the minimum date for that category.

Hello, 

 

I'm currently working on a PowerAutomate solution that in theory would take a SharePoint list, pull out the unique fields and then find the minimum date that is associated with that unique field. 

 

Into the sausage making: 

 

I have a column within a SharePoint list called "Project Group", and I have multiple items that can be part of that particular project group. The unique concern is there can be multiple dates associated with a single "Project Group", but I only am concerned with capturing the minimum date and writing that value to a different column in a SP list. 

 

Through a Union, I can pull the unique "project groups", but I'm stuck on how to then get the minimum dates associated with that particular project group. 

 

Capture.PNG

 

Capture.PNG

 

Any help on next steps would be greatly appreciated! 

8 REPLIES 8
Super User II
Super User II

hi @Skiroy  you can use get Item and use more options to add a Filter so you can add the ID from dynamic content from your firts get items action.



Did I answer your question? Please consider to Mark
my post as a solution! to guide others :winking_face:

Proud to be a Flownaut!


If you want you can follow me at www.christianabata.com Quieres contenido en español? Síguenos en Power Automate LA
Super User II
Super User II

Hello @Skiroy ,

since you already have the unique project groups, I'd loop through the project groups and for each used 'Get items' action that would:

  • filter only items for the specific project group
  • order results by the date column in ascending order
  • return top count of 1 (only the single item that belongs to the project group and has the earliest date)

The screenshot below is just an example, you should adjust the Filter Query and Order By fields according to the list

image.png

 



[ If I have answered your question, please Accept the post as a solution. ]
[ If you like my response, please give it a Thumbs Up. ]

[ ... and if you like my response, you might like also the tips and solutions on my Power Automate related blog ]

Hey Tom, 

 

These things are always difficult to explain in full detail. 

 

So the initial SP list has about 700 items, which have about 40 or 50 unique project groups, and ultimately I have another column in the initial SP list that will house the lowest date for each unique project group via update item. 

 

The compose union gives me the list of 40 unique project groups, but I'm not sure what to put in the filter query in the second "get items" '[unique project group]' as the unique project groups are housed in the union array.

 

@tom_riha  

Hello @Skiroy ,

you have the project groups stored in the array, so to process them one by one you will use 'Apply to each' action. Inside this 'Apply to each' you'll use the 'Get items' action with the filter. The [unique project group] part of the filter is the current item (project group in your case) processed by the 'Apply to each' loop, it's represented by the dynamic content 'Current item'.

Example: if you've got an array [ "project_group1", "project_group2",...], and you use that array as an input of 'Apply to each' with the Filter Query: ProjectGroup eq 'Current item'.

  • 1st loop: Current item = project_group1, the Filter Query will be translated as: ProjectGroup eq 'project_group1'
  • 2nd loop: Current item = project_group2, the Filter Query will be translated as: ProjectGroup eq 'project_group2'

But remember to use the internal name of the Project Group column in the filter.

image.png



[ If I have answered your question, please Accept the post as a solution. ]
[ If you like my response, please give it a Thumbs Up. ]

[ ... and if you like my response, you might like also the tips and solutions on my Power Automate related blog ]

Hey @tom_riha , 

 

Thanks for the break down of using current item in the second 'get items' filter query. 

 

For some reason when I run the get items it's doing the compare / filter on the created category name from the select function and the actual value. 

 

Looks something like: 

 

Project_x0020_Group eq '{"ProjectGroup":"Q1 2019"}'

 

 and of course I get a null value as an output because the project group is not called "ProjectGroup":"Q1 2019"

 

I guess the question, and it's probably a dumb one is how to reference the actual value (i.e., 'Q1 2019') from the output of the compose function above. Instead of just the current item which is "items('Apply_to_each')" , I tried to reference items('Apply_to_each')?['ProjectGroup/Value'] that didn't work either. 

 

I believe we're close. 

 

 

Hello @Skiroy ,

if you remove the /Value part from the reference it should work, the data is directly in the "ProjectGroup" key.

items('Apply_to_each')?['ProjectGroup']

 



[ If I have answered your question, please Accept the post as a solution. ]
[ If you like my response, please give it a Thumbs Up. ]

[ ... and if you like my response, you might like also the tips and solutions on my Power Automate related blog ]

Hey @tom_riha , 

 

For some reason it wasn't working before, but now it's running and pulling 59 unique project groups, with an associated earliest date (for most of them). The only one that isn't populating correctly is the first project group I have (earliest date is 1/4/2019, but for some reason it's picking up the second earliest date of 1/11/2019, not sure what's going on there, but anyways. 

 

So we now have our list of unique project groups, and an output from the second get items 2 that has the associated lowest date. 

 

How would we go about looping through all 700 records, where if the project groups match, then update item (different column within the same sharepoint list), with the lowest date associated with that project group. (honestly that is just a stop gap, the ideal solution would have it calculate -120 days from that lowest date, and that would be the value in the different column within the same sharepoint.

 

one step at a time! 

 

 

Hello @Skiroy ,

once you get the lowest date, store it in some variable (to avoid unnecessary 'Apply to each' when using that date, you can also subtract the 120 days when setting the variable with the addDays(...) expression). Then repeat the 'Get items' step with the same filter, but this time without the limit on number of items. That will give you all items for given project, and you can loop through them and update each of them with the new date (from the variable). 

This part of the flow would go like this:

  • Initialize variable: string variable, to store the date and do the calculation
  • Apply to each: to process each of the projects
    • Get items: the one you already have, that gives you just 1 item with the earliest date
    • Apply to each: added automatically to process the result from 'Get items', even if it's just a single item
      • Set variable: store the date into the variable, with expression addDays([theDate],-120) you can subtract the 120 days.
    • Get items 2: the same filter as 'Get items', without the limit to just 1 item
    • Apply to each 2: added automatically to process output from 'Get items 2'
      • Condition: if the current lowest date in the item is equal to the new lowest date
        • If it's equal: do nothing
        • If it's not equal, Update item: update the current item with the variable that contains the lowest date


[ If I have answered your question, please Accept the post as a solution. ]
[ If you like my response, please give it a Thumbs Up. ]

[ ... and if you like my response, you might like also the tips and solutions on my Power Automate related blog ]

Helpful resources

Announcements
Microsoft Ignite

Microsoft Ignite

Join digitally, March 2–4, 2021 to explore new tech that's ready to implement. Experience the keynote in mixed reality through AltspaceVR!

New Super Users

Meet the Power Automate Super Users!

Many congratulations to the Season 1 2021 Flownaut Crew!

New Badges

New Solution Badges!

Check out our new profile badges recognizing authored solutions!

MPA Community Blog

Power Automate Community Blog

Check out the community blog page where you can find valuable learning material from community and product team members!

Users online (40,575)