Linq to filter and add

i have a excel with 2 columns .Column names are conversationID (string)and reminder count(integer) .I need to do +1 to the reminder whenever i receiver respective conversationID .Please give it in Linq to use it in UiPath.I tried the below code but getting validation error .
(From row In in_FailedConversations.AsEnumerable()
Let conversationID = row(“conversationID”).ToString()
Let reminderCount = CInt(row(“reminder count”))
Let updatedReminderCount = If(conversationID =ConversationID.toString, reminderCount + 1, reminderCount)
Select row.Field(Of Object)(“conversationID”), updatedReminderCount).CopyToDataTable())

Hi @tharani.natarajan

Please try this

(From row In in_FailedConversations.AsEnumerable()
Let conversationID = row("conversationID").ToString()
Let reminderCount = CInt(row("reminder count"))
Let updatedReminderCount = If(conversationID = ConversationID.ToString, reminderCount + 1, reminderCount)
Select in_FailedConversations.Clone().Rows.Add(conversationID, updatedReminderCount)).CopyToDataTable()

@tharani.natarajan

(From row In dtResult.AsEnumerable()
Where row.Field(Of String)(“conversationID”) = conversationIDToUpdate
Let updatedReminderCount = row.Field(Of Integer)(“reminder count”) + incrementAmount
Select dtResult.Rows(dtResult.Rows.IndexOf(row))(1) = updatedReminderCount).CopyToDataTable()

Hi @tharani.natarajan

In your linq expression you have given extra close braces at last. After the CopytoDatatable()) remove the close brace and give like this .CopyToDataTable().

(From row In in_FailedConversations.AsEnumerable()
 Let conversationID = row("conversationID").ToString()
 Let reminderCount = CInt(row("reminder count"))
 Let updatedReminderCount = If(conversationID = ConversationID, reminderCount + 1, reminderCount)
 Select row.Field(Of Object)("conversationID"), updatedReminderCount
).CopyToDataTable()

Hope it helps!!

you can add it to other datatable

(From row In in_FailedConversations.AsEnumerable
Let conversationID = row(0).ToString
Let reminderCount = CInt(row(1).ToString)
Let updatedReminderCount = If((conversationID).Equals(ConversationID.toString), (reminderCount + 1).ToString,“”)
Select dt.rows.add(reminderCount,updatedRemindercount)).copytodatatable

Hope it helps…

1 Like

Thanks ,But i can’t add it new datatable .

Then you can directly modify the rows in the original DataTable using “For Each”…

How to Update Data Column Values of a Data Table | Community Blog

As described in the blog: reduce the amount of data rows to the necessary number with a filter. Then update them with a For each avtivity.

Each time all the conversations’s reminder count is added with 1 .If condition isnt working .

Let updatedReminderCount = If((conversationID).Equals(ConversationID.toString), (reminderCount + 1).ToString,“reminderCount”)
try this…

same issue.All the reminder count is added +1