How to lookup data in a SharePoint list in Power Automate
Posted On December 2, 2020
“I have two SharePoint lists, list A and list B, how to get all “lookup” data from list B that link to list A using Power Automate?”
Lookup to another SharePoint list in Power Automate is implemented using the ‘Get items’ action. It’s a similar process as when you implement lookup on list of approvers for approval processes. The only difference is in the filter you use. In the previous post it was a user, here it’s any column with unique data. It can be text or number, but for connected items it must have the same value in both lists. That column will be used in the ‘Filter Query’.
Implement the lookup
First step is to add the ‘Get items’ action to your flow. This action should lead to the 2nd list. 1st list is the one where the flow is running, 2nd list contains the lookup data.
This is also where you define the ‘lookup’ functionality adding the ‘Filter Query’. Telling the action to return only items where the unique column has the same value. In an example below, it’s the ‘Title’ column which is unique.
Output of this action will be ‘value’ dynamic content. It’s an array with all items from the 2nd list that fit the filter.
Process the lookup result
As already stated, the output from the ‘Get items’ action will be an array. And to get any value from the array, Power Automate will automatically add ‘Apply to each’. Keep in mind that everything inside the ‘Apply to each’ will run for each item returned.
If there’s just 1 item, you can skip the next step and process it directly.
But if there’re e.g. 5 items, the ‘Apply to each’ will run 5 times. That being said, before using the lookup data in a task/email/anywhere else, you should preprocess it. You don’t want to send e.g. 5 emails, you want 1 email with data from 5 items. Therefore, you should convert it from an array into a single string variable in the loop. The example below will append data in ‘Rating’ column from multiple items into a single variable.
That might be the only action you need inside the ‘Apply to each’. Once you append data from all the items into a variable, you can use the variable wherever you need. Without any additional loops.
Building a lookup to another SharePoint list has three equally important parts. You must ‘Get items’ first, and then process them accordingly. If you skip the ‘Get items’ action then there’re no lookup items. If you skip the ‘Filter Query’ on the unique column, you’ll get all items from the 2nd list. And if you try to use the ‘lookup’ data directly, without appending into a variable, you’ll get many repeated actions (emails, tasks…).