Ask AI
Skip to main content

Filter by a condition

Function: Filter by a condition

This action helps you narrow down a list of items based on specific criteria you define. Imagine you have a long list of customers, products, or tasks, and you only want to see the ones that meet certain requirements. This action allows you to do just that, providing you with a count of the items that match your condition.

Input

  • List: Select the list of items you want to filter. This could be a list of customers, orders, products, or any other collection of data in your application.
  • Condition: Enter the rule or condition that items in the list must meet to be included in the filtered result. For example, you might want to filter for items where "Price is greater than 50" or "Status is 'Active'".
  • List Object Attribute (Optional): If your list contains complex items (like a list of customer records, where each record has properties like 'Name', 'Email', 'Status'), use this input to specify which property within each item you want to apply the condition to. For example, if you want to filter customers by their 'Status', you would enter 'Status' here. If your list contains simple values (like a list of numbers or text), you can leave this blank.

Output

  • Result: A number indicating the count of items found after applying the filter. This number tells you how many items from your original list matched your specified condition.

Execution Flow

Real-Life Examples

Example 1: Filtering a list of products by price

You have a list of products and want to know how many are priced above a certain value.

  • Inputs:
    • List: [Product A \(Price: 10\), Product B \(Price: 75\), Product C \(Price: 20\), Product D \(Price: 120\)]
    • Condition: Price > 50
    • List Object Attribute: Price
  • Result: 2 (Because Product B and Product D meet the condition)

Example 2: Filtering a list of tasks by completion status

You have a list of tasks and want to quickly see how many are still pending.

  • Inputs:
    • List: [Task 1 \(Status: Completed\), Task 2 \(Status: Pending\), Task 3 \(Status: In Progress\), Task 4 \(Status: Pending\)]
    • Condition: Status == 'Pending'
    • List Object Attribute: Status
  • Result: 2 (Because Task 2 and Task 4 meet the condition)

Example 3: Filtering a list of numbers

You have a simple list of numbers and want to count how many are even.

  • Inputs:
    • List: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
    • Condition: item % 2 == 0 (Assuming 'item' refers to the current number in the list)
    • List Object Attribute: (Leave blank, as the condition applies directly to the list items)
  • Result: 5 (Because 2, 4, 6, 8, and 10 meet the condition)