647
Views
2
Comments
How to group a list based on one attribute and apply aggregate function on another
Question

Hi Team,

I have a list of records [{ key & value }] pairs and need to sum the value by grouping the key. Is there any Outsystems default action available to do this manipulation on list objects ?

Thanks,

KJ


2024-07-05 14-16-55
Daniël Kuhlmann
 
MVP

Hi Karthik,

You can do this in either two ways, using aggregates or using SQL queries.

Regards,

Daniel

2024-11-07 03-28-42
Stuart Harris
Champion

Hi Karthik,

Daniel is quite correct if you are working with a list of entities.

Additionally, if the list is a structure then you will have to perform a for loop and manually add the values.

There is a DynamicLinq component that could do it, but it is probably over engineering your requirement to use this.

It would be possible to create an extension to do this, however it would not be compile safe, as the attribute to sum would be provided as text. Although, not a bad idea for an addition to the MathUtils component.

Based on your question, I have added an Idea to add list operations which will perform sum, average and some other mathematical operations.

I hope this helps.

Kind regards,

Stuart

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.