Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8061275
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T10:17:05+00:00 2026-06-05T10:17:05+00:00

This is going to be a two part question. I am trying to build

  • 0

This is going to be a two part question.

I am trying to build a data structure for use with the Google Charts API (specifically, their data table).

Here is my code as it stands now:

return Json.Encode(
    RMAs
    .Where(r => r.CreatedDate.Year > DateTime.Now.Year - 4) //Only grab the last 4 years worth of RMAs
    .GroupBy(r => new { Problem = r.Problem, Year = r.CreatedDate.Year, Quarter = ((r.CreatedDate.Month) / 3) })
    .Select(r => new { Problem = r.Key.Problem, Year = r.Key.Year, Quarter = r.Key.Quarter, Count = r.Count() })
);

This gets me very close. This gets me an array similar to the following:

{"Problem":"It broke!","Year":2012,"Quarter":2,"Count":3},
{"Problem":"It broke!","Year":2012,"Quarter":1,"Count":1}

But, what I want is for the data to be grouped further by the “Problem” property so that the quarter is an array for each problem (this makes the data structure much easier to iterate over). An example of the desired structure:

{"Problem":"It broke!",
    {"Year":2012,"Quarter":2,"Count":3},
    {"Year":2012,"Quarter":1,"Count":1}
},
{"Problem":"Some other problem",
    {"Year":2012,"Quarter":1,"Count":31}
}

The second part of the question: How can I ensure that I have data for each quarter (again, this makes it much easier to iterate over for building the data table with the API), even if a “Problem” did not occur in that quarter? Using the same example as last time:

{"Problem":"It broke!",
    {"Year":2012,"Quarter":2,"Count":3},
    {"Year":2012,"Quarter":1,"Count":1}
},
{"Problem":"Some other problem",
    {"Year":2012,"Quarter":2,"Count":0}
    {"Year":2012,"Quarter":1,"Count":31}
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T10:17:08+00:00Added an answer on June 5, 2026 at 10:17 am
    1. Add the following to your query:

      .GroupBy(x => x.Problem)
      .ToDictionary(g => g.Key, g => g.Select(x=>new { Year=x.Year, Quarter=x.Quarter, Count = x.Count }));
      
    2. You have to insert the following before .ToDictionary() above:

      .Select(g =>
        new { 
          Key = g.Key, 
          Items = 
            g
              .GroupBy(r => r.Year)
              .SelectMany(gy =>
                gy.Concat(
                  Enumerable.Range(1,5)
                    .Where(q => !gy.Any(r=>r.Quarter == q))
                    .Select(q => new { Problem = g.Key, Year = gy.Key, Quarter = q, Count = 0 })
                )
              )
        }
      )
      

    I think… try it out 🙂

    I would advise against following this approach, however, and create “empty” records on the client, to avoid excessive bandwidth use.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've spent two days on this and have gotten nowhere. I'm trying to use
This is a two part question: Part 1 First, dealing with calculating the entropy
Two part question Part one: I am trying to create an ASynchronous request to
This is a two part question. The first is a specific question about DataSets
This is really a two part question, since I don't fully understand how these
This is a two-part question about adding a third-party library (JAR) to an Android
Hey everybody, this is what I have going on. I have two text files.
Hey this is going to be one of those dumb questions. I am trying
ok I have two strings. (I use this for a language library system to
I suspect that this is going to sound like a stupid question, but, having

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.