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/join/merge conte...
Power Automate
Answered

Group/join/merge content from one array based on unique key in a new array

(0) ShareShare
ReportReport
Posted on by

Hi Forum,

I have been reading a lot and found several similar post but with multiple arrays. In my case I'm looking for a Power Automate flow that have only one array that I want to clean and group based on a unique id.

 

My array: (every time 2 periods per unique id)

 

 

 

[
{
"id": "770",
"period": "2023-05",
"count": "12"
},
{
"id": "770",
"period": "2023-06",
"count": "13"
},
{
"id": "2027",
"period": "2023-05",
"count": "64"
},
{
"id": "2027",
"period": "2023-06",
"count": "72"
}
]

 

 

 

 

My expected result:

 

 

 

[
{
"id": "770",
"2023-05": "12",
"2023-06": "13"
},
{
"id": "2027",
"2023-05": "64",
"2023-06": "72"
}
]

 

 

 

 

Thank you very much in advance for the help

 

Cheers

Chris

Categories:
I have the same question (0)
  • lbendlin Profile Picture
    8,716 Super User 2026 Season 1 on at

    Your expected result is not in a good format.  Would be better like 

     

    [
    {
    "id": "770",
    "items":[{"period": "2023-05","count": "12"},
     {"period": "2023-06","count": "13")]
    },
    {
    "id": "2027",
    "items":[{"period": "2023-05","count": "64"},
     {"period": "2023-06","count": "72"}]
    }
    ]

     

    Would that be acceptable?

  • Verified answer
    v-xiaochen-msft Profile Picture
    Microsoft Employee on at

    Hi @ChrisBI ,

     

    I made a sample for you.

    vxiaochenmsft_0-1689304882462.png

    vxiaochenmsft_1-1689304890332.png

    vxiaochenmsft_2-1689304935553.png

    vxiaochenmsft_3-1689304982515.png

    vxiaochenmsft_4-1689305020709.png

    "@{items('Apply_to_each_2')?['period']}":"@{items('Apply_to_each_2')?['count']}",

     

    vxiaochenmsft_5-1689305050481.png

    "{@{variables('var2')}"id":@{items('Apply_to_each')}}"

    json(slice(outputs('Compose'),1,add(length(outputs('Compose')),-1) ))
    vxiaochenmsft_6-1689305076543.png

     

    vxiaochenmsft_7-1689305105314.png

     

    Best Regards,

    Wearsky

  • CH-22072116-0 Profile Picture
    on at

    Hi lbendlin,

    Thank you soo much for your feedback, unfortunately I need one level... can't work with embedded arrays.

    The solution from v-xiaochen-msft works fine !

     

    Thanks

  • CH-22072116-0 Profile Picture
    on at

    Hi Wearsky,

     

    Amazing solution! I was going in the right direction, until For Each 2 I did exactly what you did. Then I started struggling... you really helped a lot and pointed me in the right direction. That JSON(SLICE I would never have found out about it...

    Thank you soo much for helping me out so quickly.

     

    Have a nice weekend

    Chris

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

Season of Sharing Community Challenge Launch!

Jump in, show your community spirit, and win prizes!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the May Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
Valantis Profile Picture

Valantis 463

#1
Valantis Profile Picture

Valantis 463

#3
11manish Profile Picture

11manish 264

Last 30 days Overall leaderboard