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

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Group By two columns a...
Power Automate
Unanswered

Group By two columns and sum another column

(0) ShareShare
ReportReport
Posted on by 499

Hi Community,

I have an array and find a sum using GroupBy with two columns.

{
    "body": [
        {
            "AccountID": "345789",
            "Unit": "Unit1",
            "Incentive": "2500"
        },
        {
            "AccountID": "345789",
            "Unit": "Unit1",
            "Incentive": "2500"
        },
        {
            "AccountID": "12345",
            "Unit": "Unit2",
            "Incentive": "5000"
        },
        {
            "AccountID": "12345",
            "Unit": "Unit2",
            "Incentive": "5000"
        }
    ]
}

I should be able to GroupBy AccountID,Unit and Sum the values and below is the result
[
    {
        "AccountID": "345789",
        "Unit": "Unit1",
        "Incentive": "5000"
    },
    {
        "AccountID": "12345",
        "Unit": "Unit2",
        "Incentive": "10000"
    }
]

Categories:
I have the same question (0)
  • SaiKrishnaGudluru Profile Picture
    499 on at

    @Paulie78 please share your thoughts on this.

     

  • Chriddle Profile Picture
    8,436 Super User 2025 Season 2 on at

    I'm not Paulie78, but I still post my thoughts 😉

     

    Chriddle_0-1717502604751.png

    Compose

    Your JSON

     

    Select

    From

    chunk(
    	union(
    		xpath(
    			xml(json(concat('{"Root":{"Item":', body('Compose'),'}}'))),
    			'//Item/AccountID/text() | //Item/Unit/text()'
    		),
    		json('[]')
    	),
    	2
    )

    Map AccountID

    first(item())

    Map Unit

    last(item())

    Map Incentive

    xpath(
    	xml(json(concat('{"Root":{"Item":', body('Compose'),'}}'))),
    	concat('sum(//Item[AccountID="', first(item()), '" and Unit="', last(item()), '"]/Incentive)')
    )

    Chriddle_1-1717502747181.png

     

  • SaiKrishnaGudluru Profile Picture
    499 on at

    hahaha... @Chriddle , thank you for the response. I will try and update you.

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 522 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 364 Moderator

#3
abm abm Profile Picture

abm abm 243 Most Valuable Professional

Last 30 days Overall leaderboard