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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:52:32+00:00 2026-05-26T03:52:32+00:00

I have a huge dataTable (around 500k-600k rows). I wanted to compute rows based

  • 0

I have a huge dataTable (around 500k-600k rows). I wanted to compute rows based on some specific columns.
Ex: I have 3 columns name ID, type and value. I wanted to compute ‘value’ column based on ‘Type’. I have done it using DataRow Filter – first get the unique ‘ID’, then for each ‘type’ compute value. This logic gets really complex and take longer to process. I’m not very good in LINQ, so i was wondering if i can do it better using LINQ or any other way?

DataTable:

ID       type      value  
--------------------------------
2         100         5

2         100         6

2         200         10

3         200         8

3         200         9

4         100         10

4         200         15

The output i’m looking for is:

ID     Type          Value

2       100            11

2       200            10

3       200            17

4       100            10

4       200            15
  • 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-26T03:52:33+00:00Added an answer on May 26, 2026 at 3:52 am

    I think what you’re looking for is something like this. Obviously, where I’ve used <int>, you would need to replace with proper types as appropriate.

    var output = from row in table.AsEnumerable()
                 let id = row.Field<int>("ID")
                 let type = row.Field<int>("type")
                 group row by new { id, type } into grp 
                 select new 
                 {
                     ID = grp.Key.id,
                     Type = grp.Key.type,
                     Value = grp.Sum(r => r.Field<int>("value"))
                 };
    

    This is going to result in rather simple code, but it should not arguably be more efficient than a well written loop (and, of course, if you can offload this to the database instead, you will generally be better off). However, all things held equal, Linq code is pretty well optimized and efficient. If you have doubt about efficiency, measure. Run both your existing code (if you have it) and code from answers and see where you stand.

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

Sidebar

Related Questions

I have a huge form that has around 110 fields columns (single row) that
I have a huge database with some 100 tables and some 250 stored procedures.
i have a GridView bound to a DataView. Some columns in the DataView's table
I have huge table with 1 million records, i would like to modify some
I have write this code to create a gridview with 3 columns DataTable dt
i have huge project that contains around 200 jars, when i prepare release maven
I have some functions that have huge inputs (some of them has 28 etc),
We have huge stack of xml files (around 5000+ files) possibly about 80 MB
We have huge codebase and some classes are often used via reflection all over
I have a production app that tracks a product catalog. Some customers have huge

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.