I have a scenario which is having two columns in that required group of data at a time regarding the company code in excel.please find the below screenshot
regarding every company code which showing ex:5002 regarding that company code i need to get as group
Hi @Jyothi1
=> Read Range Workbook
Output → dt
=> Use below syntax in Assign:
resultDt = (From row In dt.AsEnumerable() Group row By CompanyCode = row.Field(Of Double)("Company") Into Group Select result = New Object() {CompanyCode, String.Join(",", Group.Select(Function(r) r.Field(Of String)("Payer")))}) _ .Select(Function(x) dt.Clone().Rows.Add(x)).CopyToDataTable()
=> Write Range Workbook resultDt
.
data.xlsx (10.5 KB)
Regards
exact which the query given i have written but not working throwing error
any idea why this expression is getting exception
Hi @Jyothi1
What is the exception you are getting? can you please share the screenshot of excel please.
Regards
Hi @Jyothi1
I think you have made some changes in the code. please do not change the query and use the exact query given above.
Regards
i Havent changed anything except the variable
Hi @Jyothi1
Try this:
resultDt = (From row In dt.AsEnumerable() Group row By CompanyCode = row.Field(Of Double)("Company") Into Group Select result = New Object() {CompanyCode, String.Join(",", Group.Select(Function(r) r.Field(Of String)("Payer")))}).Select(Function(x) dt.Clone().Rows.Add(x)).CopyToDataTable()
Attached xaml file:
Sequence98.xaml (9.3 KB)
Regards
Issue marked
a correctly formatted LINQ Query Syntax will fix the issue and we can also enhance readability by
it is throwing the error again with
Assign: Unable to cast object of type ‘System.Double’ to type ‘System.String’.
It is not about the LINQ it is about the data
Have a check on the Data and check
- all Company values - are there proper Numbers
- all Payers values - are there expected payers
Give a try at:
(From row In dt.AsEnumerable()
Group row By CompanyCode = row.Field(Of Double)("Company") Into grp=Group
Let ra = New Object() { CompanyCode, String.Join(",", grp.Select(Function(r) r("Payer").toString.Trim)) }
Select res = dt.Clone().Rows.Add(ra)).CopyToDataTable()
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.