LinQ to group by with two columns and count

Hi,

I have a scenario where I have to group by “ColumnC” and “ColumnD” and then get the count for those each distinct groups. Can someone provide me a linQ query? I can create logically, but it might be good to write a linQ than writing pages of UiPath code.

I need something like

Monday ------ 8.30 am ------5
Monday-------9.30 am -------4
Monday -------11.00 am -------10
Tuesday-------8.30 am ------6
Tuesday------- 11.30 am -------- 8
Wednesday---------9.30 am -------15
Wednesday --------11.30 am -------2

etc

prepare an empty datatable with 3 cols: Day, Time, Count - w.g. with Build DataTable - dtResult

Assign Activity:
dtResult =

(From d in yourOriginDataTable.AsEnumerable
Group d by k1=d("Col1Name").toString.Trim, k2=d("Col2Name").toString.Trim into grp=Group
Let ra = new Object(){k1,k2, grp.Count}
Select r = dtResult.Rows.Add(ra)).CopyToDataTable

In case that the Timing needs a more detail analysis have a look here for some debugging / analysis techniques:

1 Like

Hi @ppr This is how It’s printing. Seems like I am declaring the counter incorrectly. I declared it outside of the assign

check for the corrected typo:
Let ra = new Object(){k1,k2, grp.Count}

Thank you very much, it worked!

Perfect, so we would like to ask you for closing the topic as described here:

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