I’m trying to write a linq query to group data from a datatable by year\month.
I’ve managed to group by one or the other but not both…
Dim q = From p As DataRow In DTCalls.Rows _
Group By Year = p("DATE").Year _
Into CALLS = Count(p("CALL_ID")) _
Select Year, CALLS
How do I group\order by year THEN month within the same query?
Source data:
DATE CALL_ID
2012-05-01 23:52:44 6587
2012-02-03 09:17:41 6562
2012-05-01 06:32:41 6565
2012-02-03 12:47:41 6565
2011-05-31 08:37:41 6511
Expected output:
DATE COUNT
2011-05 1
2012-02 2
2012-05 2
You need to group by an anonymous type of two properties(year+month). You also need to apply the
Keykeyword in VB.NET.Anonymous Types (Visual Basic)