Ambiguity in loop variable #item when using contains within reduce in Data Flow Expressions.

Sathyajit Loganathan 0 Reputation points
2025-03-12T22:37:55.83+00:00

I am trying to use a contains function within a reduce function. If I were to perform some comparison on the two items how would I accomplish this?

Would the #item loop variable within the contain override the #item loop variable in the reduce function?

Example use-case:

reduce(
	split($disallowedCharacters, ''),
	false(),
	#acc || contains(split(fieldName, ''), #itemFromReduce != #itemFromContain),
	#result
)
Azure Data Factory
Azure Data Factory
An Azure service for ingesting, preparing, and transforming data at scale.
11,343 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Amira Bedhiafi 29,711 Reputation points
    2025-03-13T09:45:47.4166667+00:00

    You need to explicitly differentiate between the loop variables in the outer and inner scopes. Unfortunately, ADF Data Flow Expressions do not support renaming loop variables directly. However, you can work around this limitation by using intermediate variables or restructuring your logic.

    • Use an intermediate variable to store the #item from the reduce function.
    • Use a different variable name for the inner contains function.
    
    reduce(
    
        split($disallowedCharacters, ''),
    
        false(),
    
        #acc || contains(
    
            split(fieldName, ''),
    
            #itemFromReduce != #itemFromContain
    
        ),
    
        #result
    
    )
    
    

    If you cannot rename the loop variables, you can use intermediate variables to store the values temporarily:

    
    reduce(
    
        split($disallowedCharacters, ''),
    
        false(),
    
        #acc || (
    
            #tempItemFromReduce = #item,
    
            contains(
    
                split(fieldName, ''),
    
                #tempItemFromReduce != #item
    
            )
    
        ),
    
        #result
    
    )
    
    

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.