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 / Create a final array f...
Power Automate
Answered

Create a final array from json data with conditions

(0) ShareShare
ReportReport
Posted on by 2
Hi all,
I'm new to power automate and I'm kind of struggling with this problem.
 

If the code AND land are the same then add this json part to final_array.


Next if the next json part has the same code and land, then add size and value to the previous
one,while every other part of the json stays the same.
If code AND land are NOT the same then skip and add as a new json part to final_array.

 
final_array [ ]
 
json_data
[
    {
        "size": 1,
        "code": "300",
        "content": "xyz",
        "land": "AB",
        "value": 5
    },
    {
        "size": 1,
        "code": "300",
        "content": "xyz",
        "land": "AB",
        "value": 10
    },
    {
        "size": 1,
        "code": "400",
        "content": "abc",
        "land": "KK",
        "value": 12
    }
]
 
End Result should look like this:
 
[
    {
        "code": "300",
        "content": "xyz",
        "land": "AB",
        "size": 2,
        "value": 15
    },
    {
        "code": "400",
        "content": "abc",
        "land": "KK",
        "size": 1,
        "value": 12
    }
]
 
 
Categories:
I have the same question (0)
  • Verified answer
    Chriddle Profile Picture
    8,713 Super User 2026 Season 1 on at
    Create an array of unique keys and use xpath to query your json and sum the values:
     
     
    Select Keys
    From: outputs('Compose')
     
    Map:
     
    code
    item()['code']
    land 
    item()['land']
     
    Select
    From:
    union(
    	body('Select_Keys'),
    	json('[]')
    )
    Map:
     
    code
    item()['code']
    content
    xpath(
    	xml(json(concat('{"Root":{"Item":', outputs('Compose'),'}}'))),
    	concat('string(//Item[code="', item()['code'], '" and land="', item()['land'], '"]/content)')
    )
     
    land
    item()['land']
     
    size
    xpath(
    	xml(json(concat('{"Root":{"Item":', outputs('Compose'),'}}'))),
    	concat('sum(//Item[code="', item()['code'], '" and land="', item()['land'], '"]/size)')
    )
    value
    xpath(
    	xml(json(concat('{"Root":{"Item":', outputs('Compose'),'}}'))),
    	concat('sum(//Item[code="', item()['code'], '" and land="', item()['land'], '"]/value)')
    )
     
     

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 Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Congratulations to the June Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
David_MA Profile Picture

David_MA 261 Super User 2026 Season 1

#2
11manish Profile Picture

11manish 185

#3
Haque Profile Picture

Haque 168

Last 30 days Overall leaderboard