Count and GroupBy

Count and GroupBy

  

Hello

I have an entity, which I can group into two different groups

I have also applied the count function on the group, so I have the count of the groups

Is it possible to store the seperate counts in local variables?

Hi

What do you mean by separate count in local variable.Do you want to assign the value from aggregate to local variable? If yes, create one local variable and assign that count value to it.

Suraj Borade wrote:

Hi

What do you mean by separate count in local variable.Do you want to assign the value from aggregate to local variable? If yes, create one local variable and assign that count value to it.


Hi Suraj

The only output availabe for the entity is the group be attribute and count, so i wanted to know how to assign the correct value to the correct variable?


As per my understandings, you have done group by on id and then count on grouped by column. How did you achieve this because I don't see count function for the grouped column.

Hello Praj

The output of your aggregate will be a list with the number of records equal to the number of groups, each one with its own count.

Iterate through the list, and check the group (using a switch, or IFs) to store the count in the correct variables.

Just for curiosity, why do you need to store in local variables? Maybe there is a better way to do what you want, but we need to know what you want to achieve.

Cheers

Solution

In addition to what Eduardo said, if you have a List and you want specific elements from that List, there's the nifty ListFilter Action (from System). It allows you to quickly get an element (or multiple) from a List. Depending on the size of the list and the number of elements needed, this might result in cleaner code than a For Each with Ifs or a Switch, without too much of a speed penalty.

Solution

Suraj Borade wrote:

As per my understandings, you have done group by on id and then count on grouped by column. How did you achieve this because I don't see count function for the grouped column.

Hi Suraj

You have to first use the count function, then apply the groupby function on that attribute

Cheers

Prajjwal