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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T12:44:04+00:00 2026-06-16T12:44:04+00:00

Got a situation here, though I have a few ways to solve the problem

  • 0

Got a situation here, though I have a few ways to solve the problem but I’m very much feeling that it’s not the best way to solve as I’m doing it now. Let me try to explain my problem first. From Database I get an IEnumerable of NavReturnModelSP where NavReturnModelSP is a simple model class like

public class NavReturnModelSP
{
    public string Scheme_Name { get; set; }
    public DateTime Date { get; set; }
    public double ReInvest_Nav { get; set; }
}

Now I need to first order the set by Scheme_Name & Date & then need to rebase each Scheme & Date pair value to the base of 100 for proper comparison between schemes from the very first date. I CAN’T CHANGE THE DATABASE OUTPUT. Below is a picture for your referance, Hope it’ll explain you the problem better.

The problem

And I’m solving it now just by looping through….
where ‘data’ is the IEnumerable of NavReturnModelSP

var preModel = data.OrderBy(x => x.Scheme_Name).ThenBy(x => x.Date).ToList();
var preScheme = "";
var firstNav = 0d;
for (int i = 0; i < preModel.Count(); i++)
{
    if (preModel[i].Scheme_Name != preScheme)
    {
        firstNav = preModel[i].ReInvest_Nav;
        preModel[i].ReInvest_Nav = 100;
    }
    else
    {
         if (preModel[i - 1].ReInvest_Nav != 0) // Just a check, nothing special.
             preModel[i].ReInvest_Nav = 100 * preModel[i].ReInvest_Nav / firstNav;
    }
    preScheme = preModel[i].Scheme_Name;
}

Now I have ‘preModel’ with the rebased data in the ReInvest_Nav column. But I feel that I’m not using the proper power of the CPU & I can use Parallal programming / PLINQ to minimize the time frame as for 100000 rows for loop will be quite slow. Can someone please guide me for that.

Thanks & Happy New Year 🙂
Sanjay

  • 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-16T12:44:05+00:00Added an answer on June 16, 2026 at 12:44 pm

    Try this:

    var preModel = data.GroupBy(x => x.Scheme_Name)
                       .Select(x => new {
                                          Scheme_Name = x.Key, 
                                          Max = x.Max(m => m.ReInvest_Nav), 
                                          Data = x
                                        })
                       .SelectMany(x => x.Data.Select(y => new {
                                           y.Scheme_Name, 
                                           y.Date, 
                                           y.ReInvest_Nav, 
                                           Rebased = y.ReInvest_Nav / x.Max * 100
                                         }))
                       .OrderBy(x => x.Scheme_Name)
                       .ThenBy(x => x.Date)
                       .ToList();
    

    I can’t promise this will be any faster, but it avoids explicit loops.

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

Sidebar

Related Questions

Here's the situation: I've got a class that is doing too much. It's mainly
NEWBIE ALERT! Here's the situation. I've got an Android ListActivity class (AppWindow) that contains
really strange situation I got here. I have 2 classes. @Entity public class CategoryData
Here is my situation: I have an interface that each of my controls use
I have a specific situation where I've got an object that I want to
So, here's my situation. We have a department that needs the ability to use
I know there probably is, but here's the situation: I have a mega menu
I got a little confusing situation here when I use the Context from django.template.
Here's the situation: I've got two partial views. One has a form. What needs
Here is the situation: I've got a command I'm running: import subprocess foo =

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.