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

  • Home
  • SEARCH
  • 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 414371
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T18:16:34+00:00 2026-05-12T18:16:34+00:00

I tried out some code to get the running total and subtotal ,but that

  • 0

I tried out some code to get the “running total” and “subtotal” ,but that did yield successful result.

When the code is given:

var salesPeople =
new SalesPerson[] 
{ 
new SalesPerson{Name="Ricky", RegionCode="R001",SalesAmount=100,
SalesDate=Convert.ToDateTime("01/Jan/2009")},

new SalesPerson{Name="Mark", RegionCode="R001",SalesAmount=200,
SalesDate=Convert.ToDateTime("02/Jan/2009")},

new SalesPerson{Name="Jon", RegionCode="R001",SalesAmount=400,
SalesDate=Convert.ToDateTime("10/Jan/2009")},

new SalesPerson{Name="Ricky", RegionCode="R001",SalesAmount=100, 
SalesDate=Convert.ToDateTime("05/Jan/2009")},

new SalesPerson{Name="Mark", RegionCode="R001",SalesAmount=200,
SalesDate=Convert.ToDateTime("07/Jan/2009")},

new SalesPerson{Name="Jon", RegionCode="R001",SalesAmount=250,
SalesDate=Convert.ToDateTime("11/Jan/2009")},

new SalesPerson{Name="Ricky", RegionCode="R002",SalesAmount=50,
SalesDate=Convert.ToDateTime("01/feb/2009")},

new SalesPerson{Name="Mark", RegionCode="R002",SalesAmount=120,
SalesDate=Convert.ToDateTime("02/feb/2009")},

new SalesPerson{Name="Peter", RegionCode="R002",SalesAmount=30,
SalesDate=Convert.ToDateTime("10/feb/2009")},

new SalesPerson{Name="Ricky", RegionCode="R002",SalesAmount=400, 
SalesDate=Convert.ToDateTime("05/feb/2009")},

new SalesPerson{Name="Mark", RegionCode="R002",SalesAmount=70,
SalesDate=Convert.ToDateTime("07/feb/2009")},

new SalesPerson{Name="Peter", RegionCode="R002",SalesAmount=60,
SalesDate=Convert.ToDateTime("11/feb/2009")}

};


How can i find the Total,SubTotal,RunningTotal similiar to the following one.

       (1) Running Total Based on Region and Month

                            Sales History
        -------------------------------------------------------------
        Region Code     Name       MonthyRunningTotal      SalesDate          
                                                           (By Month)

        -------------------------------------------------------------

         R001           Ricky        100                   01/Jan/2009
         R001           Ricky        200                   05/Jan/2009


         R002           Ricky         50                   01/feb/2009
         R002           Ricky        450                   05/feb/2009  

         R001           Mark         200                   02/Jan/2009
         R001           Mark         400                   07/Jan/2009


         R002           Mark        120                    02/feb/2009
         R002           Mark        190                    07/feb/2009  

         R001           Jon         400                    10/Jan/2009
         R001           Jon         650                    11/Jan/2009  

         R002           Peter        30                    10/feb/2009
         R002           Peter        90                    11/feb/2009  

and

             (2)  Total and Subtotal based on Region and Month

                  Sales History (Based on Region and Month)
        -------------------------------------------------------------
        Region Code     Name       MonthyRunningTotal      SalesDate          
                                                           (By Month)    
        -------------------------------------------------------------

         R001           Ricky        100                   01/Jan/2009
         R001           Ricky        100                   05/Jan/2009

                        Total        ----
                                     200 
                                     ----  

         R002           Ricky         50                   01/feb/2009
         R002           Ricky        400                   05/feb/2009  

                         Total       ----
                                     450
                                     ----    

         R001           Mark         200                   02/Jan/2009
         R001           Mark         200                   07/Jan/2009

                        Total       -----
                                     400
                                    -----  

         R002           Mark        120                    02/feb/2009
         R002           Mark         70                    07/feb/2009  

                        Total       ----
                                    190
                                    ----  

         R001           Jon         400                    10/Jan/2009
         R001           Jon         250                    11/Jan/2009  
                                    ----
                                    650
                                    ----

         R002           Peter        30                    10/feb/2009
         R002           Peter        60                    11/feb/2009  
                                    -----
                                     90
                                    ----- 
  • 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-12T18:16:34+00:00Added an answer on May 12, 2026 at 6:16 pm

    use Group and Sum:

    from s in SalesPeople 
    group s by s.RegionCode into g 
    select new {Category=g.Key, Sum = g.Group.Sum(p => p.SalesAmount)}
    

    See also http://www.develop-one.net/blog/2007/11/11/LINQSumAndGroupBy.aspx

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

Sidebar

Related Questions

I tried searching around, but I couldn't find anything that would help me out.
I am very interested in streaming data for web-applications. I have tried out some
Silly question, but I'm unable to figure out.. I tried the following in Ruby:
I have more than one OpenID as I have tried out numerous. As people
I've tried figuring out this problem for the last 2 days with no luck.
Well I tried to figure out is this possible in any way. Here is
Long ago I tried to sort out my system between local, web server and
For a long time i have tried to work out the best way to
I've tried my best and cannot figure out what happened here. It worked fine
I was trying to check out a project from SVN using Eclipse. I tried

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.