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 8867327
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T16:59:58+00:00 2026-06-14T16:59:58+00:00

I have a list of ForecastData and it looks like this: public class ForecastData

  • 0

I have a list of ForecastData and it looks like this:

public class ForecastData
{
    public string SalesID {get;set;}
    public string Customer {get;set;}
    public string Vendor {get;set;}
    public string Division {get;set;}
    public int Year {get;set;}
    public decimal Amount {get;set;}
}

I need to display a list of every distinct “SalesID” for each “Customer” that has an Amount > 0 where the year is THIS YEAR.

Currently, I’m grouping by Customer, but because I can have multiple “Amounts” for the same Customer and SalesID in my dataset, I’m not getting the results I expect. My results show:

  1. Customer1 User1 $100
  2. Customer1 User1 $200
  3. Customer1 User1 $300
  4. Customer1 User2 $100
  5. Customer1 User2 $200

But what I want is

  1. Customer1 User1 $600
  2. Customer1 User2 $300

Here’s my expression:

var forecasts = (List<ForecastData>)cache.Get(_RAW_FORECAST_DATA_KEY, null);

foreach(var custGroup in forecasts.Where(f => f.Year == DateTime.Now.Year).GroupBy(f => f.Customer))
{
    if(custGroup.Count() > 1) // There's more than one forecast for this customer
    {
        foreach(var instance in custGroup)
        {
            toReturn.Add(new MultipleCustomer(custGroup.Key)
            {
                Salesperson = instance.SalesPersonId,
                Forecast = instance.Amount
            });
        }
    }
}

return toReturn;
  • 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-14T16:59:59+00:00Added an answer on June 14, 2026 at 4:59 pm

    I think if you change your query so that you have an “outer” GroupBy and an “inner” GroupBy, it will solve your problem:

    var forecasts = (List<ForecastData>)cache.Get(_RAW_FORECAST_DATA_KEY, null);
    
    var forecastGroups = forcasts
        .Where(f => f.Year = DateTime.Now.Year)
        .GroupBy(f => f.Customer)
        .Where(grp => grp.Count() > 1)
        .Select(grp => new { Key = grp.Key, SalesGroups = grp.GroupBy(f => f.SalesId) });
    
    foreach(var custGroup in forecastGroups)
    {
        if(custGroup.SalesGroups.Count() > 1)
        {
            foreach(var salesGroup in custGroup.SalesGroups)
            {
                toReturn.Add(new MultipleCustomer(custGroup.Key)
                {
                    Salesperson = salesGroup.Key,
                    Forecast = salesGroup.Sum(f => f.Amount)
                });
            }
        }
    }
    
    return toReturn;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have List collection with around 35,000 strings Typical string looks like this: <i>füüs</i>ampri
I have List like this List<string> items = new List<string>(); items.Add(-); items.Add(.); items.Add(a-); items.Add(a.);
I have List<Custom> where Custom is class Custom { public int id; public String
I have list like this: var list = new List<string>(); This list contains lets
i have list of items IList with data that looks list this: GenId TestMode
I have list of dictionaries like this: [{'X': '10'}, {'time': '08:34:51', 'load': 28.27, 'memory':
I have list of number like this: 146, 168 174, 196 230, 252 258,
I have list like this: listvalues = [True, True, False, True, False, 24, somestring,
I have list items, with a span, set to inline-block and floated right. This
I have list of links, like: <div class=links> <a href=# class=link1>link 1</a> <a href=#

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.