xflow Help

Conditional Calculation

Conditional Calculation node allows users to define conditions to segment data and perform calculations based on those conditions within a data workflow.

Configuration

Upon selecting the Conditional Calculation node, users are presented with the following configuration options along with if and else by default.

Defining Calculations Conditions

New Column: Displays a default column name, which can be edited based on requirements.

Data Type Selection: Choose the data type for the new column from the dropdown:

  • Number

  • String

  • Datetime

  • Data

Add Rule: Define individual conditions to segment data based on specific criteria.

Add Group: Combine conditions using logical operators (AND, OR, NOT) to create complex segmentation rules.

Creating Conditions

Field Selection: Users choose the column or field from the dataset on which the condition will be applied.

Logic Condition: Users select from a range of logical operators such as

  • equal to (==)

  • not equal to (!=)

  • Contains

  • Not contains

  • Is empty

  • Is not empty

  • Is null

  • Is not null.

Input Value: Users input the value against which the selected column will be evaluated.

Calculation based on condition

After defining segmentation conditions, users can perform calculations based on these conditions using if, elif, and else statements:

  • if: Mandatory initial condition.

  • elif: Additional conditions that can be added if needed.

  • else: Optional default condition if none of the previous conditions are met.

Users can choose from three calculation methods:

  • Static Value: Assign a fixed value based on the selected data type.

  • Simple Calculation: Perform basic mathematical operations.

  • Advanced Calculation: Define complex expressions using available fields and operators.

Allow Duplicates toggle button

The Allow Duplicates option in the Conditional Calculation node determines how the node handles multiple rows that satisfy the same condition.

  • Enabled: The node preserves all rows that meet the defined conditions, even if multiple rows have identical values.

  • Disabled: The node deduplicates rows that have identical values after applying the defined conditions.

Example Usage

Consider a dataset containing customer information:

Dataset

CustomerID

CustomerName

PurchaseAmount

1

John Doe

1200

2

Jane Smith

1800

3

Michael Johnson

800

4

Emily Brown

2500

Problem Statement: A retail company wants to calculate bonuses for its sales team based on their individual sales performances. Each salesperson may have multiple sales records for the same period, and the company wants to ensure that each sale is considered separately for accurate bonus calculations.

  • Condition 1: PurchaseAmount > 2000 (20% discount)

  • Condition 2: 1500 <= PurchaseAmount <= 2000 (15% discount)

  • Condition 3: PurchaseAmount < 1500 (10% discount)

  • Default: Apply a 5% discount if no conditions are met.

Configuration:

  • New Column: DiscountAmount

  • Data Type Selection: Number

If Condition

  • Field Selection: Select "DPurchaseAmount" column.

  • Logic Condition: Choose greater than (>)

  • Input Value: 2000

    Logic Representation: ('PurchaseAmount' > 2000)
  • Calculation: Choose Advanced and perform calculation

    [PurchaseAmount]*0.8

Else If Condition

  • Field Selection: Select "DPurchaseAmount" column.

  • Logic Condition: Choose between

  • Input Value: 1500 and 2000

    Logic Representation: ('PurchaseAmount' between 1500 and 2000)
  • Calculation: Choose Advanced and perform calculation

    [PurchaseAmount]*0.85

Else If Condition

  • Field Selection: Select "DPurchaseAmount" column.

  • Logic Condition: Choose less than

  • Input Value: 1500

    Logic Representation: ('PurchaseAmount' < 1500)
  • Calculation: Choose Advanced and perform calculation

    [PurchaseAmount]*0.9

Else Condition

  • Calculation: Choose Advanced and perform calculation

    [PurchaseAmount]*0.95

Resultant Output

  • Allow Duplicates is disabled

CustomerID

CustomerName

PurchaseAmount

DiscountedAmount

1

John Doe

1200

1080

2

Jane Smith

1800

1530

3

Michael Johnson

800

720

4

Emily Brown

2500

2000

  • Allow Duplicates is enabled

CustomerID

CustomerName

PurchaseAmount

DiscountedAmount

1

John Doe

1200

1080

1

John Doe

1200

1140

2

Jane Smith

1800

1530

2

Jane Smith

1800

1710

3

Michael Johnson

800

720

3

Michael Johnson

800

760

4

Emily Brown

2500

2000

4

Emily Brown

2500

2375

Last modified: 21 February 2025