Skip to main content

Notifications

Community site session details

Community site session details

Session Id : kZBGLozbKGo/luHP1aZ+VW
Power Automate - Building Flows
Unanswered

How do I loop through multiple columns in power automate?

Like (0) ShareShare
ReportReport
Posted on 24 Dec 2022 14:25:41 by 432

I'm able to go through a single column by initializing a variable as so:

choiceColumns

[

"Column1"

]

Apply To Each

    input: choiceColumns

    append to another variable (columnValueList) the columns value

    *Name: columnValueList

    *Value: triggerBody()[items('Apply_to_each')][0]['Value']

 

So what this does is grabs the value of Column1 and stores it in a variable, my issue is that I have many columns, and I want to loop through all of them and grab all their values and append to same variable.

 

 

choiceColumns

[

"Column1",

"Column2",

]

this doesnt work for me.

 

also, as an aside, why does this code work when the way the brackets are arranged looks wrong?

triggerBody()[variables('myVariable')[variables('loopIndex')]]

also written as:

triggerBody()[variable[variable()]]  ? can someone help me understand what this line of code does written in this strange way?

  • grantjenkins Profile Picture
    11,059 Super User 2025 Season 1 on 25 Dec 2022 at 03:51:34
    Re: How do I loop through multiple columns in power automate?

    I'm not sure if you're wanting to do this for multiple items (rows) and whether it's from a SharePoint list or not, but that's what I've gone with which should show the main logic.

     

    The list I'm using for this example is:

    grantjenkins_0-1671936983914.png

     

    The full flow is below. I'll go into each of the actions.

    grantjenkins_1-1671937018513.png

     

    Get items retrieves all the items from my list.

    grantjenkins_2-1671937044141.png

     

    Fields is a Compose that contains the list of fields I want to retrieve values from. Note that this would be a list of internal field names. In this example, I just want the values from field_02 and field_03.

    grantjenkins_3-1671937098894.png

     

    Apply to each iterates through each of the items returned.

    grantjenkins_4-1671939726844.png

     

    Select will return the values from each of the fields in your array. The input is your Fields array, and the expression used is:

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

    grantjenkins_5-1671939825216.png

     

    Filter array uses the output from Select and removes any blank values (if one of the field values was blank in the list). The expression used is below. Note that the condition uses is not equal to and Choose a value is left as it is.

    item()

    grantjenkins_8-1671940046234.png

     

    Join then takes the output from Filter array and joins them by whatever you want. In this example, I'm joining them by a semicolon.

    grantjenkins_7-1671940035076.png

     

    After running the flow, we get the following output for each of the two items (rows) in the list.

    grantjenkins_9-1671940179697.png

     

    grantjenkins_10-1671940197810.png

     

  • dperez13 Profile Picture
    432 on 24 Dec 2022 at 21:26:39
    Re: How do I loop through multiple columns in power automate?

    the issue with my data is that i need to both loop through xml that looks like this

    <field_15>dataIneed</field_15> (field_15 thats the  column name of a single line of text column)

    and <field_14>{

    value:"choice1" (column value i need from field_14 who is a column name as well, but of a choice column, hence the different structure)

    }

    but because field_14 can be any column name i need some logic to filter which ones i want.

     

    if field_14 choice equals a certain value

    i need field_15 single line of text value

    also check field_16, and so forth

  • Amit_Sharma Profile Picture
    1,569 Super User 2024 Season 1 on 24 Dec 2022 at 19:01:41
    Re: How do I loop through multiple columns in power automate?

    Hi @dperez13 

     

    I have created sample for you to get multiple choice column value in apply to each action.

     

    1. use get items Action to retrieve all the item.

    Amit_Sharma_6-1671908585129.png

     

     

    2. After that use one compose action (XML) 

    Amit_Sharma_1-1671908095571.png

     

     

    xml(json(concat('{"root": { value:', outputs('Get_items')?['body/value'], '}}')))

     

     

     

    Expression:

    xml(json(concat('{"root": { value:', outputs('Get_items')?['body/value'], '}}')))

     

    For highlighted text provide correct name according to your actions

     

    3. Then use one apply to each action and iterate on items which return by get items Action.

    Amit_Sharma_2-1671908189366.png

     

    4. then use one compose action (JSON)

    Amit_Sharma_3-1671908226431.png

     

     

    join(xpath(outputs('XML'), concat('//value[ID=', items('Apply_to_each')?['ID'], ']/TestChoice/Value/text()')), ', ')

     

     

     

    Expression: 

    join(xpath(outputs('XML'), concat('//value[ID=', items('Apply_to_each')?['ID'], ']/TestChoice/Value/text()')), ', ')
     
    For highlighted text provide correct name according to your actions name and list column name.
     
    (don't use space between your multiple choice column here even you are used in your list also you check its name in output of get item action ).
     
    Complete Flow
    Amit_Sharma_4-1671908388839.png

    List

    Amit_Sharma_5-1671908421104.png

     

      

    -------------------------------------------------------------------------
    If I have answered your question, please mark post as Solved.
    If you like my response, please give it a Thumbs Up.

     

     

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

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Markus Franz – Community Spotlight

We are honored to recognize Markus Franz as our April 2025 Community…

Kudos to the March Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 146,702 Most Valuable Professional

#2
RandyHayes Profile Picture

RandyHayes 76,287 Super User 2024 Season 1

#3
Pstork1 Profile Picture

Pstork1 66,017 Most Valuable Professional

Leaderboard
Loading started