0

This is my simple query:

<table class="table-bordered">
        @foreach (var data in Model.TableEE.Select(x => new { Month = x.Month, Year = x.EmpIn, Amount = x.EmpOut }))
        {
            <tr>
                <td>@data.Month</td>
                <td>@data.Year</td>
                <td>@data.Amount</td>
            </tr>
        }
</table>

The result from above query:

enter image description here

I need to transform into this format:

         |Jan|Feb|Mar|Apr|May|Jun|Jul   |Aug   |Sep|Oct|Nov|Dec|
CY2015   | 0 | 0 | 0 | 0 | 0 | 0 | 0    | 0    | 0 | 0 | 0 | 0 |
CY2016   | 0 | 0 | 0 | 0 | 0 | 0 |165947|165947| 0 | 0 | 0 | 0 |

Can anyone help me to achieve this? Thanks!

meJustAndrew
  • 6,011
  • 8
  • 50
  • 76
Suhandy Chow
  • 249
  • 1
  • 4
  • 14
  • And what have you tried yourself? It is a very simple task. – Tavo Sep 13 '16 at 08:55
  • Possible duplicate of [Is it possible to Pivot data using LINQ?](http://stackoverflow.com/questions/167304/is-it-possible-to-pivot-data-using-linq) – fubo Sep 13 '16 at 09:00

1 Answers1

0

Now I Understand what exactly you are looking for, and you will have to do a GroupBy(y => y.Mounth) and an OrderBy(y => y.Year). Then you will be able to present data in the format you want.

Sorry that I don't write the entire snippent of code, but I don't have your structure so I will not be sure it will compile.

meJustAndrew
  • 6,011
  • 8
  • 50
  • 76