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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T05:30:21+00:00 2026-05-13T05:30:21+00:00

From the Data,I have to find datewise total and GrandTotal the appropriate row should

  • 0

From the Data,I have to find datewise total and GrandTotal the appropriate row should be
filled with (***) when not applicable).

OrderID     OrderAmt   OrderDate                                              
----------- ---------- --------------------
1           10.50      2003-10-11 08:00:00
2           11.50      2003-10-11 10:00:00
3           1.25       2003-10-11 12:00:00
4           100.57     2003-10-12 09:00:00
5           19.99      2003-10-12 11:00:00
6           47.14      2003-10-13 10:00:00
7           10.08      2003-10-13 12:00:00
8           7.50       2003-10-13 19:00:00
9           9.50       2003-10-13 21:00:00

Output

OrderID     Order Date OrderAmt   Sub Total  Grand Total 
----------- ---------- ---------- ---------- ----------- 
1           10/11/2003 10.50       ***         ***            
2           10/11/2003 11.50       ***         ***           
3           10/11/2003 1.25       23.25        ***        
4           10/12/2003 100.57      ***         ***            
5           10/12/2003 19.99      120.56       ***        
6           10/13/2003 47.14      ***          ***           
7           10/13/2003 10.08      ***          ***           
8           10/13/2003 7.50       ***          ***           
9           10/13/2003 9.50       74.22      218.03

What are the changes needed in the following query ?

var qry =
                (from o in ord

                 select new
                 {

                     OrdNumber = o.OrderNumber,
                     OrdDate = o.OrderDate,
                     Amount = o.OrderAmount,
                     GrandTotal = ord.Sum(p => p.OrderAmount)
                 }
                  ).ToList();
  • 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-13T05:30:21+00:00Added an answer on May 13, 2026 at 5:30 am

    Apart from being unreadable, and wildly inefficient, this should do the trick:

    var SubTotals = from o in ord
                    group o by o.OrderDate.Date into g
                        select new
                                   {
                                       Id = g.Max(x => x.OrderNumber),
                                       Amount = g.Sum(x => x.OrderAmount)
                                   };
    var qry = from o in ord
              orderby o.OrderDate
              let subTotals = SubTotals.Where(x => x.Id == o.OrderNumber)
              let grandTotal = ord.Sum(x => x.OrderAmount)
              let lastId = ord.OrderBy(x => x.OrderNumber).Last().OrderNumber
              select
                  new
                      {
                          OrderNumber = o.OrderNumber,
                          OrderDate = o.OrderDate.Date,
                          Amount = o.OrderAmount,
                          SubTotal = (subTotals.Any()
                                        ? subTotals.First().Amount.ToString()
                                        : "***"),
                          GrandTotal = (o.OrderNumber == lastId
                                        ? grandTotal.ToString()
                                        : "***")
                      };
    

    As a general disclaimer I would urge you to reconsider using linq for formatting data. Hacking up this kind of code is fine if you are tied to using only SQL, but given the chance, there is no shame in just looping over a dataset 🙂

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

Sidebar

Related Questions

I do have 500k datas. how do I find similar names from data base??
I have data from travel diaries which has been read in from a csv
I have data from two different sources that I need to combine. Some data
I have data from *.obj file. I know how draw with GL_TRIANGLES . How
I have data from tests with two lists of parts, called in and out.
I need to get some data from a column. For example I have data
I have data coming from an external system (in CSV form). The data contains
i have data below from streaming: 'ID|20120206|080500|0000001|0|1|record1|END' 'ID|20120206|080500|0000002|0|1|record2|END' 'ID|20120206|080500|0000003|0|1|record3|END' and i want to process
I have some data from log files and would like to group entries by
I have looped data from mysql, and it's a pretty long list. What's the

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.