Filter DataTable
Filters rows in a DataTable based on a filter expression. Only rows that match the filter criteria are included in the output table. This node is essential for data selection and conditional processing.
Common Properties
- Name - The custom name of the node.
- Color - The custom color of the node.
- Delay Before (sec) - Waits in seconds before executing the node.
- Delay After (sec) - Waits in seconds after executing node.
- Continue On Error - Automation will continue regardless of any error. The default value is false.
If the ContinueOnError property is true, no error is caught when the project is executed, even if a Catch node is used.
Input
- Table - DataTable to filter
- Filter - Filter expression to apply (uses DataView RowFilter syntax)
Output
- Table - Filtered DataTable containing only rows that match the filter criteria
Filter Expression Syntax
The filter uses .NET DataView RowFilter syntax. Here are common patterns:
Comparison Operators
=- Equal to<>- Not equal to>- Greater than>=- Greater than or equal to<- Less than<=- Less than or equal to
Logical Operators
AND- Both conditions must be trueOR- At least one condition must be trueNOT- Negates a condition
String Operations
- String values must be enclosed in single quotes:
'value' LIKE- Pattern matching with wildcards (%for multiple chars,_for single char)
Wildcards
%- Matches any sequence of characters*- Can also be used in some contexts_- Matches any single character
Example Usage
Simple Equality Filter
// Filter by exact match
var filter = "Status = 'Active'";
// Result: Only rows where Status column equals 'Active'
Numeric Comparisons
// Filter by age range
var filter = "Age > 18 AND Age < 65";
// Filter by minimum value
var filter = "Salary >= 50000";
// Filter by price range
var filter = "Price > 10.00 AND Price <= 100.00";
String Pattern Matching
// Find all emails from gmail
var filter = "Email LIKE '%@gmail.com'";
// Find names starting with 'A'
var filter = "Name LIKE 'A%'";
// Find names containing 'son'
var filter = "Name LIKE '%son%'";
// Find exact length patterns
var filter = "Code LIKE 'AB____'"; // Matches AB followed by 4 chars
Multiple Conditions
// Combine multiple conditions with AND
var filter = "Department = 'Sales' AND Salary > 60000";
// Use OR for alternative conditions
var filter = "Status = 'Active' OR Status = 'Pending'";
// Complex combinations
var filter = "(Age > 25 AND Age < 40) AND (City = 'New York' OR City = 'Boston')";
NOT Operator
// Exclude specific values
var filter = "NOT Status = 'Deleted'";
// Exclude pattern
var filter = "NOT Email LIKE '%@spam.com'";
Filtering with Dynamic Values
// Build filter from variables
var minAge = 21;
var department = "Engineering";
var filter = "Age >= " + minAge + " AND Department = '" + department + "'";
// Filter: "Age >= 21 AND Department = 'Engineering'"
Date Filtering
// Filter by date (format as per your data)
var filter = "OrderDate >= '2024-01-01' AND OrderDate <= '2024-12-31'";
// Recent records
var filter = "CreatedDate > '2024-06-01'";
Tips
- Always enclose string values in single quotes (
'value') - Use parentheses to group complex conditions
- Column names with spaces should be enclosed in square brackets:
[Column Name] = 'value' - Test your filter expressions with sample data first
- The filter is case-sensitive for string comparisons
- Empty or null values can be checked with special syntax:
ColumnName IS NULL - For "not null":
ColumnName IS NOT NULL - Original table is not modified; a new filtered table is returned
Common Errors
Empty Table Error
Error: Table cannot be empty. Please provide a valid DataTable.
Solution: Ensure you're passing a valid DataTable object.
// Wrong - table is null
var table = null;
// Correct
var table = /* Valid DataTable */;
Empty Filter Error
Error: Filter cannot be empty. Please provide a valid filter expression (e.g., age > 30).
Solution: Provide a valid filter expression string.
// Wrong
var filter = "";
// Correct
var filter = "Age > 30";
Invalid Filter Syntax
Error: Various syntax errors from the DataView engine
Common causes and solutions:
// Wrong - missing quotes around string
var filter = "Name = John"; // Error!
// Correct
var filter = "Name = 'John'";
// Wrong - using double quotes
var filter = 'Name = "John"'; // May cause error
// Correct - use single quotes
var filter = "Name = 'John'";
// Wrong - invalid operator
var filter = "Age == 30"; // Use = not ==
// Correct
var filter = "Age = 30";
Column Name Not Found
If you reference a column that doesn't exist in the table, you'll get an error.
// Table has columns: ["Name", "Age", "Email"]
// Wrong - column doesn't exist
var filter = "Status = 'Active'"; // Error: Status column not found
// Correct
var filter = "Name = 'John'";
Advanced Examples
Multiple Value Matching
// Match any of several values (using OR)
var filter = "Country = 'USA' OR Country = 'Canada' OR Country = 'Mexico'";
// Using IN operator (if supported)
var filter = "Country IN ('USA', 'Canada', 'Mexico')";
Null Checks
// Find rows with null values
var filter = "PhoneNumber IS NULL";
// Find rows with non-null values
var filter = "PhoneNumber IS NOT NULL";
// Combine with other conditions
var filter = "Email IS NOT NULL AND Status = 'Active'";
See Also
- Sort Table - Sort filtered results
- LINQ Query - Advanced querying with LINQ
- Lookup DataTable - Find specific values
- Get Row - Retrieve specific rows by index