cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
LCCmikecollier
Regular Visitor

How to select data from an array based on dynamic column and row headers

I have created a flow that runs when a form is completed.

 

I would like to use two of the choices in the form to select a value from a sharepoint list.

 

I can select the row using 'Get Items' and applying a Filter Query where '["Choice1"] eq [Column1]'

 

This allows me to hardcode the output value I wish to use.

 

What I would then like to do, is dynamically return a value from a column as specified by "Choice2"

1 ACCEPTED SOLUTION

Accepted Solutions

Hopefully this is what you are after.

 

I'm using the following list for this example. Note that all columns are of type Single line of text.

grantjenkins_0-1670323862294.png

 

And the following Microsoft Form.

grantjenkins_1-1670324162609.png

 

 

I'm providing two different flows here as it depends on how your internal column names get generated in your SharePoint List.

 

Assuming the internal names of your SharePoint columns match the names you have in your Microsoft Form, we would do the following.

grantjenkins_2-1670324186880.png

 

Get items will retrieve the rows where the Title (in my example) is equal to the Area that was selected in the Microsoft Form. This should only return a single item, but will still be in an array as Power Automate doesn't know how many items would be returned.

grantjenkins_3-1670324252614.png

 

Compose Output uses the following expression to extract out the value of the column we selected in our Microsoft Form.

//Note that r384d1b0fd9b14f4d83145371b5c50f6d in this instance is referring to the Field we selected in the Microsoft Form.

first(outputs('Get_items')?['body/value'])?[outputs('Get_response_details')?['body/r384d1b0fd9b14f4d83145371b5c50f6d']]

 

The expression first will get the first (only) item that was returned and pass in the Field that was selected in the Microsoft Form as the field name.

grantjenkins_4-1670324410722.png

 

And that's it.

 

HOWEVER, this will work ONLY if the internal column names in your SharePoint List match what you have in your Microsoft Form, but often this is not the case. In my example, SharePoint actually named my columns Cat1, Cat2 and Cat3 very differently. To check what the internal names are, you can add a Compose directly after Get items and pass in the value, then run your flow. In the JSON output you will see what the internal names are. In my case, the three columns were named as shown below.

grantjenkins_5-1670324653967.png

 

We definitely don't want to have these names in our Microsoft Form for users to choose, so we can instead, setup a mapping object. See full flow below for this scenario.

grantjenkins_6-1670324732689.png

 

Get items is exactly the same as the previous flow.

grantjenkins_7-1670324761987.png

 

Compose Map contains an object where the Property names match what we have in our Microsoft Form and the Property values are our internal column names.

{
  "Team": "Team",
  "Cat1": "OData__x0043_at1",
  "Cat2": "OData__x0043_at2",
  "Cat3": "OData__x0043_at3"
}

grantjenkins_8-1670324855150.png

 

Compose Field uses the following expression to return the internal column name using the Microsoft Form Field name. This will give us the internal column name that we can use in the final Compose.

outputs('Compose_Map')?[outputs('Get_response_details')?['body/r384d1b0fd9b14f4d83145371b5c50f6d']]

 grantjenkins_10-1670325044162.png

 

Compose contains the expression similar to the previous flow, but instead of passing in the Field from the Microsoft Form, it passes in the internal column name retuned from Compose Field.

first(outputs('Get_items')?['body/value'])?[outputs('Compose_Field')]

grantjenkins_9-1670325026083.png

 



----------------------------------------------------------------------

If I've answered your question, please mark the post as Solved.

If you like my response, please consider giving it a Thumbs Up.

View solution in original post

4 REPLIES 4
Ajinder31
Continued Contributor
Continued Contributor

Hello @LCCmikecollier , Are we trying to Get Items where Column value matches either Choice1 or Choice2? If Yes, Column eq 'Choice1' or Column eq 'Choice2' should work.

Please share the flow screenshot and clarify more on requirement If I misunderstood the requirement.

 

Hi @Ajinder31,

 

Choice1 is a list of areas (North, East, South, West)

Choice2 is a list of Categories (Team, Cat1, Cat2, Cat3...)

 

The list is designed as below:

AreaTeamCat1Cat2Cat3
North    
East    
South    
West    

 

Step 1) Get Items for Choice1 eq 'Area' and returned the value in the 'Team' column by selecting it from dynamic content

 

Step 2) Dynamic lookup where if Choice1 = North and Choice2 = Cat2, it would return the value in (North, Cat2)...

 

As I am always going to be doing Step 1, I thought that it may be able to just do a filter on the existing Get Items. It's all being pulled into an automatic email via Send a email (v2). I thought that I may be able to do it via an expression or a Filter Array.

Hopefully this is what you are after.

 

I'm using the following list for this example. Note that all columns are of type Single line of text.

grantjenkins_0-1670323862294.png

 

And the following Microsoft Form.

grantjenkins_1-1670324162609.png

 

 

I'm providing two different flows here as it depends on how your internal column names get generated in your SharePoint List.

 

Assuming the internal names of your SharePoint columns match the names you have in your Microsoft Form, we would do the following.

grantjenkins_2-1670324186880.png

 

Get items will retrieve the rows where the Title (in my example) is equal to the Area that was selected in the Microsoft Form. This should only return a single item, but will still be in an array as Power Automate doesn't know how many items would be returned.

grantjenkins_3-1670324252614.png

 

Compose Output uses the following expression to extract out the value of the column we selected in our Microsoft Form.

//Note that r384d1b0fd9b14f4d83145371b5c50f6d in this instance is referring to the Field we selected in the Microsoft Form.

first(outputs('Get_items')?['body/value'])?[outputs('Get_response_details')?['body/r384d1b0fd9b14f4d83145371b5c50f6d']]

 

The expression first will get the first (only) item that was returned and pass in the Field that was selected in the Microsoft Form as the field name.

grantjenkins_4-1670324410722.png

 

And that's it.

 

HOWEVER, this will work ONLY if the internal column names in your SharePoint List match what you have in your Microsoft Form, but often this is not the case. In my example, SharePoint actually named my columns Cat1, Cat2 and Cat3 very differently. To check what the internal names are, you can add a Compose directly after Get items and pass in the value, then run your flow. In the JSON output you will see what the internal names are. In my case, the three columns were named as shown below.

grantjenkins_5-1670324653967.png

 

We definitely don't want to have these names in our Microsoft Form for users to choose, so we can instead, setup a mapping object. See full flow below for this scenario.

grantjenkins_6-1670324732689.png

 

Get items is exactly the same as the previous flow.

grantjenkins_7-1670324761987.png

 

Compose Map contains an object where the Property names match what we have in our Microsoft Form and the Property values are our internal column names.

{
  "Team": "Team",
  "Cat1": "OData__x0043_at1",
  "Cat2": "OData__x0043_at2",
  "Cat3": "OData__x0043_at3"
}

grantjenkins_8-1670324855150.png

 

Compose Field uses the following expression to return the internal column name using the Microsoft Form Field name. This will give us the internal column name that we can use in the final Compose.

outputs('Compose_Map')?[outputs('Get_response_details')?['body/r384d1b0fd9b14f4d83145371b5c50f6d']]

 grantjenkins_10-1670325044162.png

 

Compose contains the expression similar to the previous flow, but instead of passing in the Field from the Microsoft Form, it passes in the internal column name retuned from Compose Field.

first(outputs('Get_items')?['body/value'])?[outputs('Compose_Field')]

grantjenkins_9-1670325026083.png

 



----------------------------------------------------------------------

If I've answered your question, please mark the post as Solved.

If you like my response, please consider giving it a Thumbs Up.
LCCmikecollier
Regular Visitor

@grantjenkins  this is exactly the solution is was looking for, thank you 🙂

Helpful resources

Announcements
Power Automate News & Announcements

Power Automate News & Announcements

Keep up to date with current events and community announcements in the Power Automate community.

Community Calls Conversations

Community Calls Conversations

A great place where you can stay up to date with community calls and interact with the speakers.

Power Automate Community Blog

Power Automate Community Blog

Check out the latest Community Blog from the community!

Top Solution Authors
Users online (4,447)