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 an array with su...
Power Automate
Answered

Group an array with summing up one of the parameters

(0) ShareShare
ReportReport
Posted on by 47
Hi all, I am trying to group and sum up my array. It should sum up the amount (Anzahl) of items with equal ids (Artikelnummer), 
 
Here is input example:
 
[
  {
    "Artikelnummer""18136",
    "Anzahl"1
  },
  {
    "Artikelnummer""18760",
    "Anzahl"1
  },
  {
    "Artikelnummer""12352",
    "Anzahl"4
  },
  {
    "Artikelnummer""12352",
    "Anzahl"5
  }
]
 
 
and I expect to get this output:
 
[
  {
    "Artikelnummer""18136",
    "Anzahl"1
  },
  {
    "Artikelnummer""18760",
    "Anzahl"1
  },
  {
    "Artikelnummer""12352",
    "Anzahl": 9
  }
]
 
The data comes from Dataverse as output of List rows action. I would prefer some solution in Dataverse (some kind of view for the table using GroupBy), unfortunately I have found any. 
Getting the output from Dataverse within List rows would be the prefferable solution but as far as I know, aggregation is not supported there. 
I have tried to use an approach with Apply to each and array variable, but faced two problems:
- the current item was not evaluated within the Condition / Apply to each
- this approach takes too long and the transformation should not take more than 1-2 seconds even if the array contains up to 100 items
Categories:
I have the same question (0)
  • Chriddle Profile Picture
    8,525 Super User 2026 Season 1 on at
    For 100 items this takes less than a second:

     
    From:
    union(
    	xpath(
    		xml(json(concat('{"Root":{"Item":', outputs('Compose'), '}}'))),
    		'//Item/Artikelnummer/text()'
    	),
    	json('[]')
    )
    Map Artikelnummer:
    item()
    Map Anzahl:
    xpath(
    	xml(json(concat('{"Root":{"Item":', outputs('Compose'), '}}'))),
    	concat('sum(//Item[Artikelnummer=', item(), ']/Anzahl)')
    )
     
    Result
  • Verified answer
    Jelle de Haas Profile Picture
    42 on at
    You can perform aggregation directly in Dataverse using FetchXML queries, which improves performance and eliminates the need for complex processing in Power Automate.
     
    In your case you can use the following FetchXML query directly in your List Rows action. Simply replace the placeholder logical names with your actual table and column logical names:
    <fetch mapping="logical" aggregate="true">
      <entity name="yourTable_logicalName">
        <attribute name="column_Artikelnummer_logicalName" alias="column_Artikelnummer_logicalName" groupby="true" />
        <attribute name="column_Anzahl_logicalName" alias="column_Anzahl_logicalName" aggregate="sum" />
      </entity>
    </fetch>
    Note: In this example, the name and alias attributes are set to the same value, which makes it easier to reference them as dynamic content in your flow. Alternatively, the alias can be different if you prefer to use a custom field name.
  • ryjan Profile Picture
    47 on at
    Thanks a lot. I have used both approaches. 

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!

Leaderboard > Power Automate

#1
David_MA Profile Picture

David_MA 112 Super User 2026 Season 1

#2
Haque Profile Picture

Haque 52

#3
Ellis Karim Profile Picture

Ellis Karim 51 Super User 2026 Season 1

Last 30 days Overall leaderboard