(From d In dtData.AsEnumerable
Group d By k=d("CODE").toString Into grp=Group
Let dv = (From dp In Depts
Let f = grp.Where(Function (f2) f2("DEPT").toString.Equals(dp)).Sum(Function (s) CInt("0" & s("AMOUNT").toString))
Select t=Tuple.Create(dp, f.toString)).ToDictionary(Of String, String)(Function (t) t.Item1,Function (t) t.Item2)
Let va = Depts.Select(Function (x) If(dv.ContainsKey(x), dv(x), Nothing)).toArray
Let ra = va.Prepend(k).toArray
Select dtReport.Rows.Add(ra)).CopyToDataTable
The above solution converts the integer values to string. Is there any way to preserve the format e.g., if the number is in integer format it should be integer or if it is in double it should be double but not string.
highly recommended is also the debugging course from UiPath Academy. Working with the watch / immediate panel allows very quickly to test and explore code / LINQ statements