158
Views
11
Comments
Solved
Sum values of columns in a table based on a condition and show them in a new table

Suppose i have a table like this in outsystems:-(The data for this table is fetched through a sql query) 

And i need to add the values of all columns in the table based on the subset for the same group i.e. after addition i need a new table which looks like this:-


Where i have added values of all subsets in AP,ABC , ABG based on the subset condition (don't mind the added up values, i have taken random values to illustrate)

so in a nutshell what i need to do is 

if Subset='VVEN':

Col1+=col1 

and so on for different subsets and display in a new table.

How do i do this ? 


2025-02-04 10-17-42
Shreelakshmi N S
Champion
Solution

Hi Satvik,

If you are performing a SQL operation, then you can do like below.

Create an Output structure

Write the below SQL query and use the structure on the Output

SELECT {SumExample}.[GroupName], SUM({SumExample}.[Col1]), SUM({SumExample}.[Col2]), SUM({SumExample}.[Col3])

FROM {SumExample}

GROUP BY {SumExample}.[GroupName]

Test the query and output will be as below

Data in the entity is as shown below

Let me know if this works for you!!

Regards,

Shree

2023-06-15 18-30-12
FRANK JOHNNY GANGUILHET

Thanks for the tip.

UserImage.jpg
SS27

can i group them by without using the Group Name column, it isn't present in my data and i need to create it on my own using conditions from subset group

2025-02-04 10-17-42
Shreelakshmi N S
Champion

What conditions you need to use? Could you please attach the oml file for reference?

UserImage.jpg
SS27

Sorry can't attatch the oml file but the conditions that i need to use are like these:- if subset=Group1Subset2 it belongs to group 1 so i need to create a new column based on subsets and group by the data accordingly

2025-02-04 10-17-42
Shreelakshmi N S
Champion

If subset = Group1subset2 then you need to create a new column which will be the sum of Col1 ? Is my understanding correct?

2025-09-04 06-33-37
Nikhil___Vijay

Hello Satvik Srivastava

First you have to group by the name 

then  right click on col1 , col2 and col3 and click on sum then 

Hope this will help you 

Regards 

Nikhil kumar vijay 


UserImage.jpg
SS27

Problem is that i don't have this as a static table nor an aggregate, the data inside the table is fetched from a SQL query which is dependent on filters set by user at runtime, so using that table I need to sum up those values and group them. Your solution is appropriate for a static table I guess. I tried using an aggregate in continuation of the refresh SQL widget in the screen action but I can't reference the entire table in that for some reason. Plus I need to bind that table to an existing table on my screen.

2025-02-04 10-17-42
Shreelakshmi N S
Champion

Hi Satvik,

What are the possible filters you have on the runtime? You have mentioned only one i.e., if subset = 'VVEN' then Col1+ = col1. Could you please explain more about the filter conditions that you have?

Regards,

Shree

UserImage.jpg
SS27

the filters aren't present in the table, VVEN or other subsets are not filters here, they are just columns.

2025-02-04 10-17-42
Shreelakshmi N S
Champion
Solution

Hi Satvik,

If you are performing a SQL operation, then you can do like below.

Create an Output structure

Write the below SQL query and use the structure on the Output

SELECT {SumExample}.[GroupName], SUM({SumExample}.[Col1]), SUM({SumExample}.[Col2]), SUM({SumExample}.[Col3])

FROM {SumExample}

GROUP BY {SumExample}.[GroupName]

Test the query and output will be as below

Data in the entity is as shown below

Let me know if this works for you!!

Regards,

Shree

2023-06-15 18-30-12
FRANK JOHNNY GANGUILHET

Thanks for the tip.

UserImage.jpg
SS27

can i group them by without using the Group Name column, it isn't present in my data and i need to create it on my own using conditions from subset group

2025-02-04 10-17-42
Shreelakshmi N S
Champion

What conditions you need to use? Could you please attach the oml file for reference?

UserImage.jpg
SS27

Sorry can't attatch the oml file but the conditions that i need to use are like these:- if subset=Group1Subset2 it belongs to group 1 so i need to create a new column based on subsets and group by the data accordingly

2025-02-04 10-17-42
Shreelakshmi N S
Champion

If subset = Group1subset2 then you need to create a new column which will be the sum of Col1 ? Is my understanding correct?

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