Hi Experts,
I have an Excel file with contain column as Differentiate and i need filter this to get filter differentiate amount only plus 5 and minus 5 in it using LINQ filter method. Please suggest me to achieve this.
Regards,
Balachander
Input.xlsx (9.1 KB)
@Balachander_Pandian
Try this:
(From row In YourDataTableVar.AsEnumerable()
Where (row.Field(Of Integer)("Differenciate") = 5 Or row.Field(Of Integer)("Differenciate") = -5)
Select row).CopyToDataTable()
@Balachander_Pandian
Try this Linq
from row in excelDT
where row.Differentiate == plus5 || row.Differentiate == minus5
select row;
Hi @Balachander_Pandian
(From row In dt.AsEnumerable()
Where row.Field(Of Double)("Differenciate") = 5 Or row.Field(Of Double)("Differenciate") = -5
Select row).CopyToDataTable
Hope it helps!!
lrtetala
(Lakshman Reddy)
October 27, 2023, 6:43am
6
Hi @Balachander_Pandian
If you want only 5 and -5 then try below code
(From row In DT1.AsEnumerable()
Where (CInt(row("Differenciate")) = 5 Or CInt(row("Differenciate")) = -5)
Select row).CopyToDataTable
If you want -5 to 5 values then try below code
(From row In DT1.AsEnumerable()
Let differentiate = row.Field(Of Double)("Differenciate")
Where differentiate >= -5 AndAlso differentiate <= 5
Select row).CopyToDataTable()
O/P:
Input (1).xlsx (10.3 KB)
Hope this helps!!
ppr
(Peter Preuss)
October 27, 2023, 8:04am
7
(From d in dtData.AsEnumerable
Let val = CDbl(d(“Differnciate”).toString.Trim
where Math.Abs(val).Equals(5)
Select r = d).CopyToDataTable
Handling empty filter result
[FirstAid] Handling of The source contains no DataRows exception - News / Tutorials - UiPath Community Forum
Please let us know if =5 or =-5 is needed or the range -5 to 5 is needed
@ppr need range between -5 to 5 is needed
lrtetala
(Lakshman Reddy)
October 27, 2023, 9:40am
10
@Balachander_Pandian
Try this
(From row In DT1.AsEnumerable()
Let differentiate = row.Field(Of Double)("Differenciate")
Where differentiate >= -5 AndAlso differentiate <= 5
Select row).CopyToDataTable()
@lrtetala I have tried this but didn’t meet the expected output as sheet3 … I am expecting output as sheet3 which you had done from your end.
Hereby i attached my output . Please advise me
Output.xlsx (29.6 KB)
Hi @Balachander_Pandian
(From row In dt.AsEnumerable()
Let differentiateValue = row.Field(Of Double)("Differenciate")
Where differentiateValue >= -5 AndAlso differentiateValue <= 5
Select row).CopyToDataTable
Output
Hope it helps!!
lrtetala
(Lakshman Reddy)
October 27, 2023, 9:45am
13
@Balachander_Pandian
(From row In DT1.AsEnumerable()
Let differentiate = row.Field(Of Double)("Differenciate")
Where differentiate >= -5 AndAlso differentiate <= 5
Select row).CopyToDataTable()
O/P:
Output.xlsx (135.0 KB)
lrtetala
(Lakshman Reddy)
October 27, 2023, 9:48am
14
@Balachander_Pandian
Check this output for your recently updated file
Output (2).xlsx (40.7 KB)
ppr
(Peter Preuss)
October 27, 2023, 11:20am
15
changed to:
(From d in dtData.AsEnumerable
Let val = CDbl(d(“Differnciate”).toString.Trim
where Math.Abs(val) <= 5
Select r = d).CopyToDataTable