UiPath Keep Filter and Append CSV Example |Video upload date:  · Duration: PT6M5S  · Language: EN

Concise UiPath tutorial showing how to keep filtered rows and append them to a CSV for reliable automation and clean data flow.

Why this matters and why you should care

If you work with CSV files in UiPath you have seen the horror show where headers duplicate and duplicates pile up like guilt. This guide shows how to Read CSV into a DataTable apply a Keep filter and safely Append CSV so you do not create a Frankenstein file. It is short practical and slightly sarcastic because you will thank me later.

Overview of the workflow

High level first so your brain does not explode. The main steps are simple and reliable:

  • Read CSV into a DataTable variable such as dtInput
  • Use the Filter Data Table activity set to Keep rows and output to dtFiltered
  • Append the filtered rows to the target CSV using Append To CSV or a StreamWriter with append true
  • Validate results and remove duplicates if needed

Step 1 Read CSV and prepare your DataTable

Use the Read CSV activity and store results in a DataTable like dtInput. Do not skip encoding checks and header validation. If your headers are spelled differently between files standardize them now. You want consistent column names and matching data types so Append does not turn into chaos.

Step 2 Apply a Keep filter with Filter Data Table

Drag in the Filter Data Table activity and choose Keep rows mode. Define your column conditions or use a custom expression and send the result to dtFiltered. This keeps only the rows you actually want and drops background noise. Think of it as selective amnesia for bad rows.

Filter tips

  • Use precise conditions on key columns to reduce false positives
  • If you need complex logic use a custom expression or run a Linq Where query then convert back to a DataTable
  • Normalize date formats and numeric types before filtering to avoid subtle misses

Step 3 Append filtered rows without duplicating headers

There are two pragmatic ways to append. Use an Append To CSV activity from a reliable package or open a StreamWriter with append set to true and write rows manually. Either way check whether the target file exists and only write headers when the file is empty. That prevents header rows from multiplying like bad decisions.

Practical checklist before writing

  • Ensure the column order in dtFiltered matches the target file
  • Write headers only if the file does not exist or has zero length
  • Use escaping for commas quotes and newlines per CSV rules

Step 4 Validate results and handle duplicates

After appending read the target CSV back into a DataTable and compare row counts or better yet use a unique key column to dedupe. If you prefer a DataTable approach merge dtFiltered into the existing DataTable with DataTable.Merge and then call DefaultView.ToTable(true) to remove duplicates. That gives you deterministic results and a clear path to automation nirvana.

Dedup strategies

  • Use a composite unique key if a single column cannot guarantee uniqueness
  • Normalize text casing and trim whitespace before comparing
  • Consider hashing key columns into a new column for fast comparisons on very large sets

Extra tips that save hours

Keep column order and data types consistent across source and target files. Apply a Distinct operation or use DefaultView.ToTable(true) when you have duplicates. Log row counts before and after appends so you can audit what changed. And add small retries around file write operations because file locks are the universe saying no.

Follow these steps to build a compact UiPath automation that reads a CSV filters rows based on rules and appends new data while keeping headers tidy and preventing duplicate entries. It is the kind of tidy automation your future self will high five you for.

I know how you can get Azure Certified, Google Cloud Certified and AWS Certified. It's a cool certification exam simulator site called certificationexams.pro. Check it out, and tell them Cameron sent ya!

This is a dedicated watch page for a single video.