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

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Group items in one array
Power Automate
Answered

Group items in one array

(0) ShareShare
ReportReport
Posted on by 108

Hello everyone!

 

I need to this below array into one array with project and its relevant hours.

 

//Current Array I have

[
  {
    "Employee": "Jhon Doe",
    "Project": "PS-023WR",
    "Hours": 16
  },
  {
    "Employee": "Jhon Doe",
    "Project": "KATE-A336",
    "Hours": 2
  },
  {
    "Employee": "Jhon Doe",
    "Project": "SITE-KJ85",
    "Hours": 15
  },
  {
    "Employee": "Jhon Doe",
    "Project": "BOAT-253F",
    "Hours": 13.5
  }
]
 
//Array I want convert in one with project + relevant hours
[
  {
    "Employee": "Jhon Doe",
    "PS-023WR": 16,
     "KATE-A336": 2,
    "SITE-KJ85": 15,
    "BOAT-253F": 13.5
  }
]
 
Note: I have this array with multiple users (Example, Jhon, Brook, David etc.)
 
Any help would be appreciated.
 
Thanks
Categories:
I have the same question (0)
  • Verified answer
    grantjenkins Profile Picture
    11,063 Moderator on at

    Hopefully this is what you're looking for.

     

    For this example, I added an extra user (David Jones) to your initial array.

    [
     {
     "Employee": "Jhon Doe",
     "Project": "PS-023WR",
     "Hours": 16
     },
     {
     "Employee": "Jhon Doe",
     "Project": "KATE-A336",
     "Hours": 2
     },
     {
     "Employee": "David Jones",
     "Project": "CAR-253A",
     "Hours": 25.5
     },
     {
     "Employee": "Jhon Doe",
     "Project": "SITE-KJ85",
     "Hours": 15
     },
     {
     "Employee": "Jhon Doe",
     "Project": "BOAT-253F",
     "Hours": 13.5
     }
     ]

     

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

    grantjenkins_3-1675601809493.png

     

    Array is a Compose that contains the initial items in your array.

    grantjenkins_1-1675601133954.png

     

    Select extracts out a list of all the Employees. It uses the following expression.

    item()?['Employee']

    grantjenkins_2-1675601187625.png

     

    Initialize variable data creates a variable of type Array called data. This will contain all the objects once the flow completes.

    grantjenkins_5-1675601942586.png

     

    Initialize variable employee creates a variable of type Object called employee. This will contain each of the employee data as we build up the data array.

    grantjenkins_6-1675602011242.png

     

    Apply to each (the outer loop) iterates over each of the employees. It uses the following expression as input which provides a unique list of employees.

    union(body('Select'), body('Select'))

    grantjenkins_7-1675602098300.png

     

    Set variable employee sets our employee variable to an object containing the current employee. The expression that you can paste directly into the action is below.

    {
     "Employee": @{item()}
    }

    grantjenkins_8-1675602248765.png

     

    Filter array uses the output from Array (Compose) and filters on the current employee. The expression used is:

    item()?['Employee']

    grantjenkins_9-1675602333931.png

     

    Apply to each item (the inner loop) uses the output from the Filter array which will iterate over each of the projects for the current employee.

    grantjenkins_10-1675602385302.png

     

    Compose uses the following expression to add a new property to the employee variable. It uses the value of the project as the name of the property, and the value of the hours as the value.

    addProperty(variables('employee'), item()?['Project'], item()?['Hours'])

    grantjenkins_11-1675602466276.png

     

    Set variable project sets our employee variable to the output from our Compose.

    grantjenkins_12-1675602512329.png

     

    Append to array variable (after the inner loop) then appends our employee object to the data array.

    grantjenkins_13-1675602593537.png

     

    This will result in the data variable (or array) containing all the employees and their associated project data as shown below:

    [
     {
     "Employee": "Jhon Doe",
     "PS-023WR": 16,
     "KATE-A336": 2,
     "SITE-KJ85": 15,
     "BOAT-253F": 13.5
     },
     {
     "Employee": "David Jones",
     "CAR-253A": 25.5
     }
    ]


    ----------------------------------------------------------------------
    If I've answered your question, please mark the post as Solved.
    If you like my response, please consider giving 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

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Congratulations to the April Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
Vish WR Profile Picture

Vish WR 921

#2
Valantis Profile Picture

Valantis 801

#3
Haque Profile Picture

Haque 588

Last 30 days Overall leaderboard