Q:

Linq: How to calculate the sales Total price and group them by product

I have a order list and I want to generate and rank the product with its total sales and quantity. With @tvanfosson's help, I can bring the grouped product detail with the following code, but how can I calculate and add up the total sales and quantity into each productListResult's object?
Can anyone help me with this?
Many thanks.    
        var productListResult = orderProductVariantListResult
                .Select(pv => pv.Product)
                .GroupBy(p => p)
                .Select(g => new 
                {
                    Product = g.Key,
                    TotalOrderCount = g.Count()
                })
                .OrderByDescending(x => x.TotalOrderCount).ToList();

A:

Something like this?
var productListResult = orderProductVariantListResult
        .GroupBy(pv => pv.Product)
        .Select(g => new 
        {
            Product = g.Key,
            TotalOrderCount = g.Count(),
            TotalSales = g.Sum(pv => pv.Sales),
            TotalQuantity = g.Sum(pv => pv.Quantity),
        })
        .OrderByDescending(x => x.TotalOrderCount).ToList();

