I have a datatable as below. I want to group by using Col3 & Col4 and take sum of Col2.
And display output as, specific column as shown below.
Input Datatable:
Col1 – Col2 – Col3 – Col4
A – 11 – AA – ABC
B – 12 – RT – EFG
C – 13 – HL – XYZ
D – 27 – AA – ABC E – 17 – AA – TUV[Robot shld not sum this, because of col4 mismatch]
F – 15 – RT – EFG
G – 24 – HL – XYZ
OutPut required:
Col1 – Col2 - Col3
AA – 38 -ABC
AA - 17 - TUV
RT – 27-EFG
HL – 37-XYZ
prepare an empty datatable with build datatable reflecting the target datacolumn strucutre:
Col1 – Col2 - Col3 Variable: dtResult
then use an assign activity
left side: dtResult
right side:
(From d in dtData.AsEnumerable
Group d by k1=d(“Col3”).toString.Trim,k2=d(“Col4”).toString.Trim into grp=Group
Let s = grp.Sum(Function (x) CInt(x(“Col2”).toString.Trim))
Ler ra = new Object(){k1,s,k2}
Select dtResult.Rows.Add(ra)).CopyToDataTable
I have a 1 linq expression, suggested by you in other topic. In this, i want some columns from DT1 & some colums to DT2. In select i tried multiple ways but ended in vain.
Can you please help me with this!!
(From DT1 In dt1.AsEnumerable()
From DT2 In dt2.AsEnumerable()
Where DT1(14).ToString().contains(DT2(1).ToString())
Select DT2).ToArray().CopyToDatatable
Kindly note: From, From is working like a Cartesian Product. We would suggest to open a new topic for this case/ question as it is new one compared to the GroupBy request.
If we keep the topics only related to one case we can support researchers by fast identifiying case and solution. With marking the solving post as solution another feedback is given and others can benefit from it.