best selling 5 products

edited 1:23AM in FastReport .NET
Hi,

I have an XML database (see Attached fıle Demodata.xml).
The tables here are Categories, Customers, Employees, Order Details, Orders, Products, ...

I cannot query on this database. So how can I show the best selling 5 products as an example ?

Thank you.

Comments

  • Hello!

    Load Demodata.xml into a DataSet, aggregate the quantity/total sales by ProductID using LINQ, and pass the resulting top 5 to the report via RegisterData:

    var ds = new DataSet();
    ds.ReadXml(“Demodata.xml”);
    
    var products = ds.Tables[“Products”].AsEnumerable();
    var orderDetails = ds.Tables[“Order Details”].AsEnumerable();
    
    var top5 = orderDetails
    .GroupBy(od => od.Field<int>(“ProductID”))
    .Select(g => new
    {
    ProductID = g.Key,
    TotalQty = g.Sum(r => r.Field<int>(“Quantity”))
    })
    .Join(products,
    s => s.ProductID,
    p => p.Field<int>(“ProductID”),
    (s, p) => new
    {
    ProductName = p.Field<string>(“ProductName”),
    s.TotalQty
    })
    .OrderByDescending(x => x.TotalQty)
    .Take(5)
    .ToList();
    
    using var report = new Report();
    report.Load(“Top5Products.frx”);
    report.RegisterData(top5, “TopProducts”);
    report.GetDataSource(“TopProducts”).Enabled = true;
    report.Prepare();
    

    In the template, bind the DataBand to the TopProducts data source and display [TopProducts.ProductName] and [TopProducts.TotalQty]

This discussion has been closed.