Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can try something like this. (NOT TESTED) Just used your c# LINQ to convert to VB</p> <pre><code>Dim test = customers.GroupBy(Function(xCustomer) xCustomer.CustId) _ .Select(Function(xCustomers) New With {xCustomers.Key, .Jan = xCustomers.Where(Function(y) y.OrderDate.Month = 1).Sum(Function(s) s.Qty), .Feb = xCustomers.Where(Function(y) y.OrderDate.Month = 2).Sum(Function(s) s.Qty)}) </code></pre> <p><strong>EDIT</strong> I have added Feb in the code. hope it helps. You can just go on adding such properties in the anonymous type.</p> <p><strong>EDIT</strong></p> <p>I used a simple VB Console app with the data that you provided in your post, and it works absolutely fine. You can try this out.</p> <pre><code>Sub Main() Dim samples As New List(Of Sample) samples.Add(New Sample() With {.Name = "a1", .Prod = 1, .Status = 1}) samples.Add(New Sample() With {.Name = "a1", .Prod = 2, .Status = 2}) samples.Add(New Sample() With {.Name = "a2", .Prod = 3, .Status = 1}) Dim test = samples.GroupBy(Function(xSample) xSample.Name) _ .Select(Function(xGrouping) New With { _ xGrouping.Key, .Prod1 = xGrouping.FirstOrDefault(Function(x) x.Prod = 1), _ .Prod2 = xGrouping.FirstOrDefault(Function(x) x.Prod = 2), _ .Prod3 = xGrouping.FirstOrDefault(Function(x) x.Prod = 3) _ }) Console.Write("Name") Console.Write(Microsoft.VisualBasic.vbTab) Console.Write("Prod1") Console.Write(Microsoft.VisualBasic.vbTab) Console.Write("Prod2") Console.Write(Microsoft.VisualBasic.vbTab) Console.Write("Prod3") Console.Write(Microsoft.VisualBasic.vbTab) Console.WriteLine() For Each test1 In test Console.Write(test1.Key) Console.Write(Microsoft.VisualBasic.vbTab) If (test1.Prod1 IsNot Nothing) Then Console.Write(test1.Prod1.Status) Else Console.Write(0) End If Console.Write(Microsoft.VisualBasic.vbTab) If (test1.Prod2 IsNot Nothing) Then Console.Write(test1.Prod2.Status) Else Console.Write(0) End If Console.Write(Microsoft.VisualBasic.vbTab) If (test1.Prod3 IsNot Nothing) Then Console.Write(test1.Prod3.Status) Else Console.Write(0) End If Console.WriteLine() Next Console.ReadLine() End Sub </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload