web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Roll up distinct multi...
Power Automate
Unanswered

Roll up distinct multi-select values from one SharePoint list item and update same column in another SharePoint list

(0) ShareShare
ReportReport
Posted on by

I have a SharePoint list of Providers. The list has a multi-select column of credentials. I also have a SharePoint list of Staff. The Staff list has a lookup column to the Provider list. It also has a multi-select column of credentials.

I would like a flow that looks at the Staff list, and by Provider, creates an array of unique credentials and updates the Provider list's credential column with the distinct values. If there are no staff attached to the provider, then the credentials column in the Provider list would be null.

So, Provider ABC has three staff members - Mary, Bob and Anna
Mary has credentials of Music, Art, Teacher
Bob has credentials of Music, Tech, Admin
Anna has credentials of Art, Knitting

The flow should look at all staff members for Provider ABC and update its credentials column with the unique values of Music, Art, Teacher, Admin, Knitting. The purpose would be for someone to look at Provider ABC and know that they have staff that can perform those duties.

I have tried getting items from Providers, then items for Staff, filtered by provider, but I end up with many "Apply to Each". Also tried appending to an array and then using the "union" compose statement, but it doesn't work when I am outside of an apply to each. Any suggestions?

Categories:
I have the same question (0)
  • the_dude Profile Picture
    361 Super User 2024 Season 1 on at

    In regards to this part:

    but it doesn't work when I am outside of an apply to each.

     

    Try initializing a variable at the start of your flow - and setting it (or appending to it) in the apply to each loop. 

    The content of the variable should be available outside the loop.

  • AnnetteM Profile Picture
    on at

    I am but I think I am getting myself lost in the apply to each statements!

    My flow works like this:

    • Get Providers list
    • Initialize a Credentials array variable
    • Apply to each based on provider
      • Get Staff list with a filter based on the provider lookup column
      • Check to see if there are no staff for the provider.
        • If none, then update the Provider list's credential column as null
        • If there are staff...
          • Apply to each based on Staff value
            • Select statement to parse the value of the multi-select credentials column
            • Apply to each based on the value of the Select statement
              • Append to the Credentials array
              • Compose statement Union(credentials array, credentials array)
        • Compose statement to get results of the Union compose
    • Update provider
    • Reset the Credentials array variable
  • Verified answer
    creativeopinion Profile Picture
    10,502 Super User 2025 Season 2 on at

    @AnnetteM The logic of your flow needs to be adjusted—you're on the right track. For complex flows I find it easier to start at the end when trying to figure out the logic. In your example, the end result is needing to update your Provider List's Credential Column with the values based on the staff selected. You'll need to also consider how you will handle updating your list when the staff are updated. However, let's keep it simple for now and start with your initial requirements.

     

    Tip: Rename your actions to keep things organized. This especially important when building a more complex flow that requires multiple instances of the same action. Run tests often to troubleshoot early! For more flow troubleshooting tips—check out This YT Tutorial: 5 Power Automate Troubleshooting FAQs and Helpful Tips for Creating Better Flows

    Get Providers

    The end of your flow will need to include an Apply to each action which loops through each Provider to update the credential column. With that in mind, you will need to first get a list of Providers you want to loop through. You've stated that you want to filter out your list where the Credentials column is empty. 

     

    Add a Get Items action. For my demo I'll be using an existing list. In my case I'll be using the Department column. For the Filter Query you'll need to use the internal column name of your Credentials column. If you aren’t sure how to get this, please refer to this section of one of my YT tutorials.

    creativeopinion_6-1704899542151.png

     

    Whenever I use a Filter Query in a Get Items action, I always like to return the count of items returned in a Compose action. This is helpful when building a flow and can also be used to troubleshoot your flow.

    Insert a Compose action. Add an Expression. Use the length() function.

    creativeopinion_1-1704899322866.png

    Select the Dynamic content tab and insert the value dynamic content from the Get Items action into the length() function.

     

    creativeopinion_2-1704899355014.png

    creativeopinion_3-1704899363592.png

    Run a test. Verify the output of the Compose action is what you expect.

     

    Get Staff

    Add another Get Items action to get the Employees. Best practice is to use the Filter Query whenever you are using the Get Items action to reduce the number of items returned. Also, your flow requires that staff have a Provider selected from a look up column. 

     

    Add a Filter query to filter out staff that don't have an empty Provider column—in my case, my look up column is Branch

    creativeopinion_8-1704899631575.png

    As above, add a Compose action to store the count of staff. This isn't necessary to make your flow work—however, it can be helpful to troubleshoot your flow. Note: This is why it's important to rename your actions. It makes it easier to identify which dynamic content belongs to which actions.

    creativeopinion_10-1704899738490.png

     

    Run a test. Verify the Compose action is outputting the correct number of staff.. 

    creativeopinion_11-1704899817537.png

     

    It's important to note you only want to run the Get Items actions once on a list in a flow. Running this action multiple times—especially inside an Apply to Each action is inefficient. Instead, you want to utilize a Filter Array action. To learn more about how to use the Filter Array action, please refer to this recent YT Tutorial I uploaded.

    Select Employees

    Add a Select action to your flow. We'll use this action to select the Provider (in my case Branch Value) and Credential (in my case Department Value).

    creativeopinion_16-1704900321836.png

    creativeopinion_17-1704900340283.png

    Run a test. Review the output. You can add as many keys and values to the Select action that you need. This reduces the data being processed to only the data your require in your flow.

    creativeopinion_18-1704900399153.png

     

    I'm also assuming that there is only a single credential selected for each staff. If not, then this action will need to be adjusted. I only have a single department selected for each employee in my case.

    Loop through Each Provider

    Add an Apply to Each action to loop through each provider. Ensure you are selecting the proper value dynamic content from the correct action.

    creativeopinion_12-1704899998602.png

    This next step is optional—however I recommend it for troubleshooting purposes. Add a Compose action to display the current Provider (in my case Branch) being looped through. Again, ensure you are selecting the proper dynamic content from the correct action. In my case, I'll use the Title column.

    creativeopinion_13-1704900072004.png

    Get the Staff for the Current Provider

    Add a Filter Array action to your flow. In the From field, insert the output from the Select action. 

    creativeopinion_19-1704900514571.png

    In the first value field, you'll need to use an expression. Start with:

    item()?['']

    In between the single quotes you need to enter the dynamic content key. Reference the key that was entered for the Provider in the Select action. The dynamic content key is case sensitive. In my case it's Branch.

    creativeopinion_20-1704900624024.png

     

    In the second value field, insert the output from the Compose action above. Alternatively, if you didn't use the Compose action you can insert the appropriate dynamic content into the second value field. 

    creativeopinion_21-1704900679977.png

    The Filter Array action is filtering out the items from the Select action where the Provider (branch in my case) is equal to the current Provider (branch) being looped through.

     

    Just as we've done above with the Get Items action, add a Compose action to store the count from the Filter Array action. Add an Expression. Use the length() function.

    creativeopinion_22-1704900812557.png

     

    Select the Dynamic content tab and insert the body dynamic content from the Filter Array action into the length() function.

    creativeopinion_23-1704900829955.png

    Run a test. Review the outputs. This is why I find the Compose action helpful. The Apply to Each action doesn't state the current item being looped through. It makes it easier to review the outputs when I know what the Apply to Each action is looping through.  

    creativeopinion_24-1704900876403.png

    In SharePoint you can group your list by Credentials (you can only do this if it's a single choice selection). Tip: Display the count for the column.

     

    creativeopinion_25-1704900946324.png

    This makes it easy to verify if the output from your flow is correct.

    creativeopinion_26-1704900962334.png

     

    Condition Check

    Add a Condition action to your flow. The purpose of this action is to check whether the Filter Array action has returned any Staff. If not, then the flow doesn't do anything. If so, it can continue on with the rest of the actions.

     

    In the first value field insert the output from the Compose action that outputs the number of staff for the current provider being looped through. 

     

    Change the operator to is not equal to. In the second value field insert 0.

    creativeopinion_1-1704909565635.png

    creativeopinion_3-1704909812583.png

     

    Select Credentials

    Take a look at the output of the Filter Array action. You'll need the dynamic content key for the next action as the dynamic content from a filter array action (most times) cannot be selected—an expression must be used. Refer to this section of a YT Tutorial I uploaded on how to get dynamic content from a Filter Array action.

    creativeopinion_2-1704909761982.png

    Add a Select action to the Yes branch. In the From field, insert the body from the Filter Array action.

    creativeopinion_28-1704911916700.png

     

    Click on this icon to change from key value to map mode.

    creativeopinion_27-1704911901716.png

     

    Insert an expression. Start with this:

    item()?['']

    Insert the dynamic content key between the single quotes. In my case it's Credential. In your case it maybe different—get the key from the Filter Array output. The dynamic content key is case sensitive.

    creativeopinion_4-1704909912010.png

    Run a test. You can't see it in the Select action which is why I copy/pasted the output into a text file. Since the Credential column is a multi-choice column, the Select action output is arrays nested inside an array. We'll need to flatten this content so it's a single array of credentials.

    creativeopinion_5-1704910076163.png

     

    Flatten the Array

    Add a Compose action to convert the array into JSON format. Replace [insert select output] with the output from the Select action. 

    {
    "Root": {
    "Items": [insert select output]}
    }
    }

    creativeopinion_6-1704910282299.png

    Run a test.

    creativeopinion_7-1704910308847.png

     

    Next add another Compose action. We'll use this action to convert the JSON to XML. 

    creativeopinion_29-1704912314947.png

    Use the xml() function.

     

    creativeopinion_11-1704910516397.png

    Click on the Dynamic content tab and insert the output from the Compose action above.

     

    creativeopinion_12-1704910535812.png

     

    Wrap the xml() function in an xpath() function. Go to the start of the expression by pressing the up arrow key. Enter xpath with an opening parenthesis.

    creativeopinion_13-1704910596794.png

    Go to the end of the expression by pressing the down arrow key. Enter a comma and single quotes. 

     

    Between the single quotes enter: 

    //*[local-name()="Value"]/text()

    Don't forget to close off the expression by entering a closing parenthesis.

    creativeopinion_15-1704911051392.png

    The xpath() function searches the XML for all elements that have the tag "Value". It extracts the value content.

     

    Run a test. The Compose action should return an array of all credentials.

    creativeopinion_16-1704911103384.png

    Unique List

    Next you'll need to return a unique list of credentials. Insert an expression and use the union() function.

     

    creativeopinion_17-1704911174344.png

    The union function combines two arrays/collections into one while removing the duplicates. Click on the Dynamic Content tab and insert the output from the Compose action above. 

     

    Add a comma. Tip: The tooltip will indicate which parameter of the expression you are defining. 

    creativeopinion_18-1704911267341.png

    Insert the output from the Compose action above again. The expression should look like this (may differ if your flow depending on how you've named your Compose action)

    creativeopinion_19-1704911347081.png

    Run a test. Review the outputs of the Compose action. It should contain unique values only.

    creativeopinion_20-1704911433817.png

    Group Actions (optional)

    Add a Scope action to your flow. I like using Scope actions in my flow to group actions together to keep my flow organized. It also allows me to quickly collapse multiple actions with a single click and reduces the vertical space the actions take up in a flow. 

    creativeopinion_21-1704911531080.png

    creativeopinion_22-1704911539364.png

    Prepare the Multi-Choice Values

    You'll need to prepare the values to patch to your SP List. Add a Select action to your flow. Insert the Output from the compose action above (the one with the array of unique credentials) into the From field.

    creativeopinion_23-1704911588452.png

    In the key field, insert the word Value with a capital V. For the value field, insert an expression. Use the item() function to return each array item.

    creativeopinion_24-1704911607408.png

    creativeopinion_25-1704911617172.png

    Run a test. Review the output an ensure the array is in the proper format.

    creativeopinion_26-1704911764136.png

    Update Item

    Add an Update Item action. Ensure you are inserting the ID dynamic content from the proper action. Remember that you are currently looping through each Provider (branch in my case). 

    creativeopinion_0-1704923003361.png

     

    You'll need to insert the appropriate dynamic content for any required fields. In this case, the title is required. Again, pay attention to the action your are inserting dynamic content from. You have two Get Items actions in your flow (this is why it's important to rename your actions!

     

    creativeopinion_1-1704923117716.png

    For the Credentials column, click on this icon to input the entire array. The array in this case is in the output of the Select action. 

    creativeopinion_2-1704923176665.png

    Again, you will need to verify that you are selecting the proper output. Note the names of your actions.

    creativeopinion_3-1704923241427.png

    Run a test. Verify that the credentials are appearing in your SP list.

    creativeopinion_4-1704923317525.png

     

     

    Hope this helps!


    If I helped you solve your problem—please mark my post as a solution .
    Consider giving me a 👍 if you liked my response! If you're feeling generous— ️  Buy me a coffee: https://www.buymeacoffee.com/acreativeopinion

    👉 Watch my tutorials on YouTube
    👉 Tips and Tricks on TikTok
     

    For more flow troubleshooting tips—check out this YT Tutorial: 5 Power Automate Troubleshooting FAQs and Helpful Tips for Creating Better Flows

    In this tutorial I cover:

     How to troubleshoot a false Condition action result

     How to get dynamic content when it isn’t selectable from the list of dynamic content

     How to troubleshoot an Apply to Each action that isn’t looping through

     How to troubleshoot a skipped Apply to Each action

     How to troubleshoot a Filter Query

     How to use a SharePoint yes/no column in a Filter Query

     How to use Compose actions to troubleshoot a Power Automate flow

    How to troubleshoot multiple emails being sent

     How to troubleshoot multiple Teams messages being sent

     

    ---

    You might find this YT Tutorial I recently uploaded helpful: 3 Mistakes YOU 🫵 are Making with the Apply to Each Action in your Microsoft Power Automate Flow

    In this video tutorial I’ll go over how to avoid these common mistakes when using the Apply to Each action in a Power Automate flow:

    1️⃣Looping through a Single Item

    2️⃣ Creating Unnecessary Nested Loops

    3️⃣ Looping through an Unfiltered Array

    At the end of the video I share a few helpful insights when it comes to using the Apply to Each action in your flow.

    I'll also cover:

     How to avoid the Apply to Each action with a single item array

     How to use the item() function to access dynamic content in an array

     How to prevent unnecessary nested Apply to Each action loops

     How to use the Select action

     How to convert an array to a string with the Select action

    How to use the Filter Query field

     How to count the number of items in an array

     How to use a condition control

     How to use the concurrency control

     How to set a top count

     How to use Compose actions for troubleshooting

     

     

     

  • AnnetteM Profile Picture
    on at

    Oh my goodness! I am tracking so far!!! You have explained very well. The only challenge I have is that the staff will have multiple credentials.

    So, the provider list has a multi-select column for credentials. The staff list has a multi-select column for credentials. The purpose of this flow is to select all the staff for a provider, parse through all of their credentials, get the unique values of all staff by provider, then update the provider's credentials column with the unique values.

    The end result is for folks to look at the provider list to determine all of the "services" they are able to provide, based on the knowledge of all their assigned staff.

    I have my flow created and ready for next steps. THANKS AGAIN!!!

  • creativeopinion Profile Picture
    10,502 Super User 2025 Season 2 on at

    @AnnetteM I've updated the original post with additional instructions.... let me know when you've reached the end.

  • AnnetteM Profile Picture
    on at

    THIS IS AMAZING! I have completed the steps you provided and have verified it is SPOT ON, and have reached the end. Thank you again!

  • AnnetteM Profile Picture
    on at

    Hello!
    Thanks for including the last update step in this flow. I have one caveat. A few of my required columns in the Provider list are multi-select choice fields, so when updating the Provider list, I select the dynamic content to grab the contents, but I receive this error:
    OpenApiOperationParameterValidationFailed. The 'inputs.parameters' of workflow operation 'Update_item' of type 'OpenApiConnection' is not valid. Error details: The API operation does not allow writing a value for parameter 'item/Ages[0]/Id'. This parameter is read only.

    Could I use a "Send an HTTP request to SharePoint" to target only the Credentials column, avoiding the required columns challenge in Update Item? Or any other suggestions?

  • creativeopinion Profile Picture
    10,502 Super User 2025 Season 2 on at

    @AnnetteM You'll need to use Select actions for each of your Multi-Choice columns. Because you have a few of these columns—I'd recommend grouping them into a Scope action. Remember to rename your actions—otherwise it'l make it difficult to determine which output belongs to which Select action.

     

    In the From field, you'll need to insert the column dynamic content.

    creativeopinion_2-1705075649873.png

    Enter Value into the key field. In the value field, insert the value dynamic content from the multi-choice column.

    creativeopinion_3-1705075672949.png

    Important: Power Automate will automatically nest this action inside an Apply to Each action. The Apply to Each action is not necessary.

    creativeopinion_4-1705075730736.png

    Pull the Select action OUTSIDE of the Apply to Each action—delete the Apply to Each action.

    creativeopinion_5-1705075761453.png

    Hope this helps!


    If I helped you solve your problem—please mark my post as a solution .
    Consider giving me a 👍 if you liked my response! If you're feeling generous— ️  Buy me a coffee: https://www.buymeacoffee.com/acreativeopinion

    👉 Watch my tutorials on YouTube
    👉 Tips and Tricks on TikTok

     

     

     

     

     

     

  • AnnetteM Profile Picture
    on at

    1000000% spot on. I am so grateful for you! Thank you so much for the swift resolution. I learned a lot! Especially the use of Select and Compose and eliminating Apply to Each!!!

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 522 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 364 Moderator

#3
abm abm Profile Picture

abm abm 243 Most Valuable Professional

Last 30 days Overall leaderboard