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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T11:48:24+00:00 2026-05-31T11:48:24+00:00

My LINQ query: Dim groupedData = (From p In pData _ Group By p.TruncParam

  • 0

My LINQ query:

Dim groupedData = (From p In pData _
                   Group By p.TruncParam Into Group) _
                  .SelectMany(Function(g) g.Group) _
                  .Select(Function(d, idx) New With { _
                      .NewParameter = String.Concat(If(d.TruncParam.Length < 5, d.TruncParam, d.TruncParam.Substring(0, 5)), idx.ToString("0000")), _
                      .FullParameter = String.Format("{0}-{1} [{2}] <{3}>", d.LabName, d.TestName, d.Parameter, d.Unit)})

Produces these results:

ID: SOLUB0000  Name: 001-AMT SOLUBL  [SOLUBLES]       <%>
ID: SOLUB0001  Name: CHEM-C4:SOL     [SOLUBLES]       <%>
ID: SOLUB0002  Name: CHEM-EMCARB:SOL [SOLUBLES]       <%>
ID: INSOL0003  Name: 001-AMT:INSOL   [INSOLUBLES]     <%>
ID: INSOL0004  Name: CHEM-AMT:INSOL  [INSOLUBLES]     <%>
ID: INSOL0005  Name: CHEM-W:INSOL    [INSOLUBLES]     <%>
ID: INSOL0006  Name: CHEM-W:INSOL    [INSOLUBLES]     <mg/l>
ID: CLRES0007  Name: 001-CL RESIDUE  [CL RESIDUE]     <ppm>
ID: SUMCA0008  Name: 001-ELEMENTS    [SUM CA K NA SI] <%>
ID: SUMME0009  Name: 001-ELEMENTS    [SUM METALS + P] <%>

When the TruncParam changes, I would like the index (idx) in the Select clause to reset to 1. So, in the list above, the Index should be SOLUB0001, SOLUB0002, INSOL0001, INSOL0002…CLRES0001, SUMCA0001, SUME0001.

How should I alter the LINQ query?

  • 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-31T11:48:26+00:00Added an answer on May 31, 2026 at 11:48 am

    You need to move the index selection inside the SelectMany statement (g.Group.Select(d, idx) => new {d, idx}) like this:

    Dim groupedData = (From p In pData _
                       Group By p.TruncParam Into Group) _
        .SelectMany(Function(g) g.Group.Select(Function(d, idx) New With { _
            .Element = d, .Index = idx}) _
        .Select(Function(d) New With { _
            .NewParameter = String.Concat(If(d.Element.TruncParam.Length < 5, d.Element.TruncParam, d.Element.TruncParam.Substring(0, 5)), d.Index.ToString("0000")), _
            .FullParameter = String.Format("{0}-{1} [{2}] <{3}>", d.Element.LabName, d.Element.TestName, d.Element.Parameter, d.Element.Unit)})
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My LINQ query is as follows Dim Query = From t In New XPQuery(Of
I have a fairly simple Linq query (simplified code): dim x = From Product
What is the equivalent lambda syntax to this linq query? Dim query = From
I have a Linq Group By query that works. Here's the query: Dim query
I've got a LINQ query in VB: Dim ss = _someClassDataSource.Sum(Function(s) TryCast(s, SomeClass).BreakdownCover) where
Can a Linq query retrieve BLOBs from a Sql Database? And how do they
Starting with the following LINQ query: from a in things where a.Id == b.Id
I have the follow Linq query ... which executes correctly: from t in Tasks
Say that I have LINQ query such as: var authors = from x in
I have the following query: Dim elementsWithPossibleCCNumbers As IEnumerable(Of XElement) = xmlTree.Descendants(). Where(Function(element) element.Attributes().

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.