I use LINQ expression should filter one column value which >-1 and <1, However, I cannot get the right data, who can help?

Requirement:
Filter datatable where “AP Invoice Number”=Blank and “AR Invoice Number” not Blank and “Issue Type”=“Price Diff” or Blank and “Diff” column value “-1< and <1 ”,

My LNQ expression is below, however, I can not get the right value.

(From d In CSVDT.AsEnumerable
Let APInvoiceNum=d(“AP Invoice Number”).tostring.Trim().toUpper()
Where String.IsNullOrWhiteSpace(APInvoiceNum)
Where d(“AR Invoice Number”).tostring.Trim().toUpper()<>“”
Let ex=d(“Issue Type”).tostring.Trim().toUpper()
Where {“PRICE DIFF”}.Any (Function(x) x.Equals(ex) OrElse String.IsNullOrWhiteSpace(ex) And Convert.ToDouble(d(“Diff”).ToString) > Convert.ToDouble(-1) And (Convert.ToDouble(d(“Diff”).ToString)<Convert.ToDouble(1)))
Select r=d
).CopyToDataTable

My LNQ result:

Hi @Lori

Could you give this a try

Filter datatable

where
“AP Invoice Number” = Blank
and
“AR Invoice Number” not Blank
and
“Issue Type”=“Price Diff” or Blank
and
“Diff” column value "-1 < and < 1 ",

(
	From d In CSVDT.AsEnumerable
	_
	Let APInvoiceNum = d("AP Invoice Number").ToString.Trim().ToUpper()
	Let ex = d("Issue Type").ToString.Trim().ToUpper()
	Let diff = Convert.ToDouble(d("Diff").ToString)
	_
	Let c1 = String.IsNullOrEmpty(APInvoiceNum)
	Let c2 = Not d("AR Invoice Number").ToString.Trim().ToUpper().Equals("")
	Let c3 = ex.Equals("PRICE DIFF") Or String.IsNullOrEmpty(ex)
	Let c4 = Math.Abs(diff) < 1
	_
	Where c1 And c2 And c3 And c4
	_
	Select r=d
).CopyToDataTable
1 Like

@kumar.varun2
Thanks for you help, seem that I made a mistake, I got the value which I want, thanks you very much!

1 Like

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