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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:40:58+00:00 2026-05-26T10:40:58+00:00

Apologies for the terrible title, I wasn’t quite sure how to phrase my problem.

  • 0

Apologies for the terrible title, I wasn’t quite sure how to phrase my problem.

I have an object that looks like:

CustAcct cust = new CustAcct();
cust.Name = "John Doe";
cust.Account = "ABC123";
cust.OrderTotal = 123.43
cust.OrderQty = 4;
cust.TransDate = "12/26/2010 13:00"

Please don’t spend too much time criticizing the next part because this really doesn’t deal with a shopping cart/Customer stuff but the idea is the same, I just wanted to use something that everyone is pretty familiar with.

An account can have more than one customer, and a customer can have more than one account.

So you have:

List<CustAcct> custList = new List<CustAcct>();
custList.Add("John Doe", "ABC123", 123.43, 4, "12/26/2010 13:00");
custList.Add("John Doe", "ABC123", 32.12, 2, "12/27/2010 10:00");
custList.Add("John Doe", "ABC321", 43.34, 1, "12/28/2010 15:00");
custList.Add("John Doe", "ABC321", 54.60, 3, "12/28/2010 16:00");
custList.Add("Jane Zoe", "ABC123", 46.45, 2, "12/28/2010 17:00");
custList.Add("Jane Zoe", "ABC123", 32.65, 1, "12/29/2010 12:00");
custList.Add("Jane Zoe", "ABC321", 67.65, 3, "12/29/2010 23:00");
custList.Add("Jane Zoe", "ABC321", 75.34, 4, "12/30/2010 08:00");

What I would like to do is get the sum of all OrderTotal and OrderQty for each Account and Customer so my output will look like:

Account    Customer    OrderTotal    OrderQty
 ABC123     John Doe    155.55          6
 ABC321     John Doe     97.94          4
 ABC123     Jane Zoe     79.10          3
 ABC321     Jane Zoe    142.99          7

I’ve been through my LINQ to Objects book and 101 LINQ Samples and can’t figure out how to go about getting this. Thanks.

  • 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-05-26T10:40:59+00:00Added an answer on May 26, 2026 at 10:40 am

    You can group and sum like this:

    from ca in custList
    group ca by new { ca.Name, ca.Account } into g
    select new {
        g.Key.Account,
        g.Key.Name,
        OrderTotal = g.Sum(o => o.OrderTotal),
        OrderQty = g.Sum(o => o.OrderQty)
    };
    

    See it in action.

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

Sidebar

Related Questions

Apologies for the terrible title, not really sure how to explain this without a
Apologies, It looks like my original question was not able to correctly explain what
Apologies for the poor question title. I have two tables, jobs and Persons-Jobs. Jobs
Apologies for a terrible title. I've been teaching myself responsive design techniques, and all
Apologies for the appalling title. I have mocked up this code to mimic an
I apologize for the terrible title...it can be hard to try to summarize an
Apologies for the confusing header. My problem is explained better in the following image:
Apologies in advance, this is a long question. (TL;DR : Does anyone have any
Apologies for using someone else's brain for this, but I'm sure this is a
Apologies, somewhat confused Python newbie question. Let's say I have a module called animals.py

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.