Increase same valued data consecutively if occurs more than once

Suppose I’ve a dataset where same data can occur more than once. If that happens I want to increase the value consecutively. I’m adding sample data and the output. same data

But I’m unable to solve it. Need some help here as I’m still learning. thank you.

have a look here:

we can solve it by groupby

I’ll look into it. Although I have little knowledge regarding “group by” and linq, I’ll try to solve it using them. I may need your help if I fail to understand it.

on the begin there is a LINQ free approach

I managed to find unique values and separate them but still not getting at my output. Sorry as i don’t have much coding knowledge to sort it out.


Do you want the output in excel only?
The input file has one column or two?
What does the input file look like?

I want the output in excel and it has two columns. First I need to concatenate Data and Data1 then the desired output will be like this new test

The output column will replace the Data Column in the end

Hi @nibir08

One way of performing this task can be as given below:

For the input table


The workflow can be designed like

The LINQ used is

	From row In inputDT
	Group row By k=row("Input").ToString
	Into grp = Group
	Let b = (
				From r In Enumerable.Range(1, grp.Count)
				Let a = If(grp.Count.Equals(1), New Object(){k, k}, New Object(){k, k+r.ToString})
				Select a
	Select b
	From rowArr In b
	Select outDT.Rows.Add(rowArr)

There is a possibility that the above query can be further optimized and reduced.
I hope @ppr and @Yoichi can help us in achieving the same.

Please refer the attached file

Increase Same Valued Data.xaml (7.6 KB)

A Slight optimization can be

	From row In inputDT
	Group row By k=row("Input").ToString
	Into grp = Group
	Let b = Enumerable.Range(1, grp.Count).Select(Function (r) if(grp.Count.Equals(1), New Object(){k, k}, New object(){k, k+r.ToString}))
	From rowArr in b
	Select outDT.Rows.Add(rowArr)
1 Like

As LINQ is less known so a hybrid approach maybe is an option to have a minimum on black box parts


Preperation and Grouping:

Member Processing:


Find starter help here:
GroupBy_1Col_AddMBRCounter_NoFirst.xaml (12.1 KB)

1 Like
(From d In dtInputData
Group d By k=d("Col1").toString.Trim Into grp=Group
Let dpr = (grp.Count = 1)
Let mba = grp.Select(Function (x,i) k & (i+1).toString).Cast(Of Object).toArray
Let nraa = If(dpr, New Object(){k},mba)
From ra In nraa
Select r=dtOutputData.Rows.Add(ra)).CopyToDataTable

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.