I need urgent help, would really appreciate if anyone can. example.xlsx (10.7 KB)
I have uploaded this xlsx as an example . Please refer to it.
My problem is when “PC” and “Vendor” are same for line items then i have to add the amount total and print that single row of the rows which are duplicate, where age is greatest.
Hope the excel file would help in uderstanding.
(From r In dtData.AsEnumerable
Group r By PC=r(“PC”), Vendor=r(“Vendor”) Into grp=Group
Select grp.OrderBy(Function ( r ) CInt(r(“Age”).toString.Trim)).Last()).CopyToDataTable
Hi @ppr,
Thanks for the reply but,
when duplicate rows are combined to one i also want to add the amount that is for matching rows amount total should be displayed in the final row. Please suggest what to do .
Also when running this workflow extra columns are adding to the excel sheet automatically.
Tested with multiple rows. This is not working exactly proper if PC number matches and Vendor number does not match then also the query is returning that row as PC number matched. Please Help.
@Shikhar_Tandon
the fastest was to come Up to the solution Could be that along the Input example you are adding the expected Output as an Excel or description. This helps for solution development
i have attached the example again and the result also in the result only one row is returned
with data 21 6 787 200 121 , 200 being the total of amounts in the duplicate rows referring PC and Vendor. Please help.
Thanks a lot it is working. Can you please tell the meaning of Enumerable.Range(0,dtData.Columns.Count - 5) this code and also please specify where i have to use column names because mostly i see you have used column names, so where is indexing. ?
Please mention column names in the code so that i can get reference, rather than indexing
thankss a lot . !! please reply
Enumerable.Range(StartIndex, Length) is creating a series e.g. 0,1,2,3,4 …
This allowed to loop over the no of unnedeed columns (count - 5, as we want to keep the 5 columns)
In this line, Columnindex are in use. I suggest to change it accordingly to your final columnnames
Let nr = New Object(){lr(0), lr(1), lr(2), grp.Sum(Function (x) CDbl(x(“Amount”).ToString.Trim)),lr(4) }
Great, that it is working. So lets close the topic with flagging the solving post as solution. Others can benefit from it.
just needed one more help, I have one main dt from where i would perform this opertion, after performing this when i will write again to that dt an extra line item would be added in the main dt so if i want to delete the rows which i have used here from the main dt what to do please help…
thanks a lott !!
thanks for the reply,
Basically what i am saying is say their one datatable named DT1 which has duplicate PC and Vendor when i applied the linq query i got the resultant line item, so what i want is that these duplicate rows be removed from the DT1 and the resultant line item to be placed in that DT1.
that is all the work happens in the same DT1, the duplicate rows with same PC and vendor to be removed and the final line item obtained when adding the amount of these rows to be placed in DT1.
thanks. Please feel free to contact if any queries.
thaks a lott!!
here you see, i am not getting the desired result, result should be
as PC and Vendor of row 3 and 4 and the age is common or greater whatever.
the final result should include the other rows which have no connection with this and row 3 and 4 should be deleted and in their place only one row should be inserted which is the result of added amount of that tow duplicate rows,
let me show you the result should be,
PC , Column1 , Vendor , Amount , Age
23 , 4 , 787 , 101 , 88
11 , 4 , 76 , (231 +12) ,777
---- ---------243----------
11 , 5 , 76 , 65 , 77
this should be the result(only these rows) rows 3 and 4 vanished and is replaced by one single row with amount as total and one with greater age.
Thanks!! looking forward for your reply.
Thanks a lot !!!
Send me the Excel with this data. But with your specification from above groups are to build for same PC and vendor. All three rows are having the Same PC and vendor Info.
An additional reaction on age were Not mentioned by you or specified. Maybe you reformulate your requirements in total and complete, so solution will Cover all points