I want to count the items status wise in a datatable.
My Datatable looks like
Date , Tkt Status
1/2/13 open
1/2/13 open
2/2/13 open
2/2/13 closed
2/2/13 closed
3/3/13 in-progress
4/3/13 closed
I want another datatable with below data in the format
Date, Open, Closed, in-progress
1/2/13 2 0 0
2/2/13 1 2 0
3/3/13 0 0 1
4/3/13 0 1 0
I want it to be done using Linq.
My attempt so far
dataQuery.Query = "Yes";
dataQuery.ViewFields = "<FieldRef Name='Created' /><FieldRef Name='tckPrty' /><FieldRef Name='tckStat' />";
dataQuery.ViewFieldsOnly = true;
tktData = tktList.GetItems(dataQuery).GetDataTable();
var newData = from row in tktData.AsEnumerable()
where groupDate(row.Field<string>("tckStat"))
group row by row.Field<string>("Created") into Status
orderby Status.Key
select new
{
key = Status.Key,
values = Status,
count = Status.Count()
};
foreach (var item in newData)
{
foreach (string s in tktStatus)
{
chartData.Rows.Add(item.key,item.count);
}
}
The function goes here
static bool groupDate(string skill) { bool value = false;
if (skill== "open")
{
value = true;
}
else
{
value = false;
}
return value;
}