Filterrr

Hi everyone,

I need some help.

I need to filter this column to exclude “-”, “0”, blank values, and the last row containing the total amount for the column.

I tried the following approach, but it isn’t working as expected.

remove condition qualifier should be “OR” not “AND”.

you also may wanna consider whether you are preserving the format of the data column while reading or you ignoring it…
if you are preserving,
you filter values should be “-” OR “0” (here zero is read as string).
else
“-” OR 0 (here 0 is taken as an integer)

SG.

Hi @dvojinovic

You can also use a LINQ for this if the filter is not working:

dt.AsEnumerable() _
.Take(dt.Rows.Count - 1) _
.Where(Function(r) Not String.IsNullOrWhiteSpace(r(“YourColumn”).ToString) _
AndAlso r(“YourColumn”).ToString.Trim <> “-” _
AndAlso r(“YourColumn”).ToString.Trim <> “0”) _
.CopyToDataTable()

It’s still the same; those rows are not being removed

@dvojinovic pls also paste your datatable values…Lets see how the values are being read..

so the Column F where you are applying filter is a decimal value which could have been read as a string since there is also a possibility that the value “-” can exist.. so in order to fit both decimal values and “-”, the data column would have been of type string.
did you try following the suggestion i made in my first response?

SG.

Hmmm… The only thing that worries me here is the special letters/characters in your column headers.

Tell me, do those column headings or positions ever change? If not, I would rather suggest you use the column reference rather than the column name. And yes, then use the “or” operand rather than “and” in your filter.

I solved the filter :slight_smile: thanks a lot. Now the problem is that when I need to enter that filtered table, it is copied like this.


this part (yellow) is unnecessary

delete the last row from the filtered table… this ensures that the last row is deleted always..
but ensure that the last row always has this item totals…
if not, you need use a different way to read data from your initial datatable source.
you can achieve this by -
option 1 :

  1. getting the last row of the sheet.(var : LastFilledRow)
  2. Passing the range of the data to read in your read range activity(eg: “C1:Z”+LastFilledRow.ToString();
  3. then apply the filters as described earlier
    and you are good!

Else if you are sure the totals will be at the last(every time)

option 2 :
Say your filtered table variable is DtFilteredData

C#

DtFilteredData.Rows[DtFilteredData.Rows.Count - 1].Delete();