Dim customerName As String = “Land of Toys Inc.” ’ Replace with the desired customer name
’ Filter the DataTable for the specified customer
Dim filteredData = sales_range.AsEnumerable().Where(Function(row) row.Field(Of String)(“CUSTOMERNAME”) = customerName)
’ Perform the LINQ query on the filtered data
Dim queryResult = (From row In filteredData
Group row By Key = New With {
.Customer = row.Field(Of String)(“CUSTOMERNAME”),
.Status = row.Field(Of String)(“STATUS”)
} Into Group
Select New With {
.Customer = Key.Customer,
.Status = Key.Status,
.TotalQuantity = Group.Sum(Function(r) r.Field(Of Integer)(“QUANTITYORDERED”))
}).ToList()
why is this not working ? is there any error , no matter what changes i do i get an error
sales_data_sample .xlsx (361.1 KB)
i use this data and what i want is i have customer column with around 10 different customers and i have a status column which has two values “shipped” and “cancelled” , there is also an quantity column where it specifies the amount of quantity shipped by the customer in each shipment.
Save to -> resultDataTable
Value to Save -> dataTable.AsEnumerable().Where(Function(row) row.Field(Of String)("STATUS") = "Shipped" Or row.Field(Of String)("STATUS") = "Cancelled").GroupBy(Function(row) New With {
Key .Name = row.Field(Of String)("CUSTOMERNAME"),
Key .Status = row.Field(Of String)("STATUS")
}).Select(Function(Group) resultDataTable.LoadDataRow({ Group.Key.Name, Group.Key.Status, CDbl(Group.Sum(Function(row) row.Field(Of Double)("QUANTITYORDERED")))}, False)).CopyToDataTable()
=> Write Range Workbook resultDataTable.
Output: sales_data_sample .xlsx (364.8 KB) sales_data_sample (1) is Input Sheet and Output is the Output Sheet