LINQ TO COUNT ELEMENTS FROM DISTINCT GROUPS

Hello everyone!

I have this datatable and i have to make a comparation between the count of elements from G1 with count of elements from D1 and like in G1 we have 2 and in D1 we have 0 and so on.
My problem thst i do not know is how to create these groups .

Hi @Andrei_Croitoru, Can you provide the expected output…!

Something like this.

Hi @Andrei_Croitoru ,

As per the Input Image provided, and based on the Groupings done on the First Columns, we can assume that you want to Group the same values and get it’s Number of Occurrences.

But the Groupings on the last column are still not clear. If you could explain How/Why the Last Column Values should be grouped in that manner, it would able us to get the logic and provide a Solution faster.

Also if you Could provide us with a Sample Excel file with the Above Input, it would be helpful to Test Solution Developed.

Practically what i need is the counter of the elements from G1 and the counter from D1. And to do a comparison between this two values. I used groups in the image to put in evidence what i need. In the future i might have to iterate through groups from T$DRAW column.

Hi @Andrei_Croitoru,

  1. Use Build Datatable Activity as dtOutput → create 3 columns Code,T$ORN0_Cnt, T$DRAW_Cnt
  2. Assign Dt = (From d In dtInput.AsEnumerable
    Group d By k1=d(0).toString.Trim Into grp=Group
    Let ra = New Object(){k1,grp.Count,grp.AsEnumerable.where(Function(x) Not String.IsNullOrEmpty(x(“T$DRAW”).tostring.Trim)).count}
    Select dtOutput.Rows.Add(ra)).CopyToDatatable

Note: I have tested with dummy record. Please refer
GroupByCount.xaml (9.5 KB)

Thanks!

Great! Thank you a lot!

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.