-4

want to Pivot this table using linq c#

My Table is here

Ani
  • 1
  • 1

1 Answers1

0

Since the question does not provide what to pivot by.. I did a pivot to count on a period of 50. Change it to your preference. Check this fiddle.

var result = myList
            .GroupBy(x => x.Branch)
            .Select(y => new {
                           Branch = y.Key, 
                           FirstPeriod = y.Count(z => z.Quantity > 100 && z.Quantity <= 150), 
                           SecondPeriod = y.Count(z => z.Quantity > 150 && z.Quantity <= 200), 
                           ThirdPeriod = y.Count(z => z.Quantity > 200 && z.Quantity <= 250)
                        }).ToList();

References:

Excellent Pivot Example

Method used in the fiddle

Yash Malla
  • 350
  • 3
  • 14
  • Thanks for your time ... I was looking for dynamic column and finally i got the solution... Once again thank You for your time and efforts... – Ani Aug 01 '18 at 12:34