Search code examples
azure-data-factory

Interpreting expression in ADF


Im stuck on this expression that someone else wrote, i seriously can´t figure out what it does? What is/ is not empty and what does it count?

countIf(IsEmpty && ActivityTypeId == 1, ContainerId)

countIf(!IsEmpty && ActivityTypeId == 1, ContainerId)

Thanks!


Solution

  • countIf is an aggregate function in azure data factory mapping data flow which counts the number of rows in the dataset based on the condition. In your expression, it counts the number of ContainerId when conditions are true.

    • countIf(IsEmpty && ActivityTypeId == 1, ContainerId): This expression counts the number of ContainerId where the IsEmpty field is true and the ActivityTypeId field is equal to 1. Here the IsEmpty is supposed to be a Boolean type. And, the activityTypeId is the integer field.

    • countIf(!IsEmpty && ActivityTypeId == 1, ContainerId): This expression counts the number of records where the IsEmpty field is false and the ActivityTypeId field is equal to 1.

    • The ! operator is a logical NOT operator that negates the IsEmpty field value. The && operator is a logical AND operator that combines the two conditions.

    This is tested with sample input data and below is the observation.

    Input data:

    batch ContainerId ActivityTypeId IsEmpty
    1 1 1 true
    1 2 1 false
    1 3 2 true
    1 4 1 true
    1 5 1 false
    1 6 2 false
    1 7 1 true
    1 8 1 false
    1 9 1 true
    1 10 2 true

    There are 4 records where IsEmpty is true and ActivityTypeId is 1, so the first expression will return the value 4; There are 3 records where IsEmpty is false and ActivityTypeId is 1, so the second expression will return the value 3.

    • Conditions are given in aggregate Transformation.

    img

    • Output of the aggregate transformation:

    enter image description here