Input: I have a excel input which contains with different teams
Example:
output: should be in another sheet with their counts
Try this linq
- Read data into datatablt dt
- Use build datatable and create 3 columns as needed with string type and dt2 as datatable
- Use assign with below
- Write back to excel
Dt2 = dt.AsEnumerable.GroupBy(function(x) x(0).ToString).Select(function(x) dt2.LoadDataRow({x.Key,x.Where(function(y) Not String.IsNullOrEmpty(y(1).ToString)).Count.ToString, x.Where(function(y) String.IsNullOrEmpty(y(1).ToString)).Count.ToString},False)).CopyToDatatable
Cheers
Hi Anil
Can I go with for each data table because it is easy to understand.
You can dot hat as well
- Assumption is all the value in column 1 are sorted if not first use sort datatable
- Then inside loop use if condition to first check if current value and previous value are equal from first column
- If equal use one more if to increment either empty total or non empty total
- If not that means there is a new value so add the old data to datatable using add data row the value and sums and then initialize sum with 0 and value with new value
Cheers
Yes we can model a so called groupby case with the help of
- DataTableVar.DefaultView… and other essential activities
Have a look here at the the first part, presenting a Non-LINQ approach:
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.