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

Group an array with summing up one of the parameters

(0) ShareShare
ReportReport
Posted on by 45
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,436 Super User 2025 Season 2 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
    45 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

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