Doubts on project

Hi All,

I have struck in a scenario and it as below.

From above I need to check the case ID column for each case ID need to check "Action\No Action’ column,
Case1: for each case ID (present more than a time) then need to remove that row if the Action\No Action contains “No Action”,

Input for scenario 1:

Case ID Date Time Action\No Action
I240518000019 07/01/2024 09:30:26.6396879 No Action
I240606000126 07/01/2024 09:31:19.7461929 No Action
I240605000093 07/01/2024 09:32:17.6146882 No Action
I240604000264 07/01/2024 09:33:20.8180588 No Action
I240518000019 07/01/2024 09:30:27.2019679 Action

Output for scenario 1:

|Case ID |Date|Time|Action\No Action|
|I240606000126|07/01/2024|09:31:19.7461929|No Action|
|I240605000093|07/01/2024|09:32:17.6146882|No Action|
|I240604000264|07/01/2024|09:33:20.8180588|No Action|
|I240518000019|07/01/2024|09:30:27.2019679|Action|

for first scenario the output should be above

Case2: if any case ID is present more than once(duplicates) then need to remove keep only Action\No Action contains “No Action” row.

Input for scenario 2:

Case ID Date Time Action\No Action
I240518000019 07/01/2024 09:30:26.6396879 No Action
I240606000126 07/01/2024 09:31:19.7461929 No Action
I240605000093 07/01/2024 09:32:17.6146882 No Action
I240604000264 07/01/2024 09:33:20.8180588 No Action
I240518000019 07/01/2024 09:30:27.2019679 Action
I240518000019 07/01/2024 09:30:26.6396879 No Action

Output for scenario 2:

Case ID Date Time Action\No Action
I240518000019 07/01/2024 09:30:26.6396879 No Action
I240606000126 07/01/2024 09:31:19.7461929 No Action
I240605000093 07/01/2024 09:32:17.6146882 No Action
I240604000264 07/01/2024 09:33:20.8180588 No Action
I240518000019 07/01/2024 09:30:27.2019679 Action

In short if any Case ID column not contains duplicate then need to remove the complete row if the column “Action\No Action” contains No action , need to keep only Action.

If any case ID is duplicate then need to delete only one row from the Action\No Action
contains No action.

thanks in advance

@naveen.s

DT1=DT.AsEnumerable() _
    .GroupBy(Function(row) row.Field(Of String)("Case ID")) _
    .SelectMany(Function(g) _
        If(g.Count() = 1, _
           g.Where(Function(row) Not row.Field(Of String)("Action\No Action").Equals("No Action")), _
           g.Where(Function(row) Not (row.Field(Of String)("Action\No Action").Equals("No Action") AndAlso g.Count(Function(r) r.Field(Of String)("Action\No Action").Equals("Action")) > 0)) _
        ) _
    ) _
    .CopyToDataTable()

It will check the Both Scenaros and delete the rows
Hope it helps

@naveen.s

Is my linq query works you. Is there any Issues

Hi @naveen.s

Please check the below zip file.

Datatable Process.zip (75.2 KB)

Let me know if you have any issues.

Regards

1 Like

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