Concatenate dynamic columns in ADF

Abhishek Vyas 101 Reputation points
2021-03-15T12:37:08.59+00:00

Hi Team,

How do we create expression builder to concatenate the dynamic columns in dataflow?
Or if there is any other way to achieve the same?

Following are the use cases where source file may have couple of columns (for addresses) which are to be combined to store in one column (FullAddress) in the sink.

a. Address1, Address2, LineAddress3 -> FullAddress (derived column)
b. Address2, Address1, City -> FullAddress (derived column)
c. City, Address2 -> FullAddress (derived column)

Please note that the order and the number of columns may vary depending on user.

Azure Data Factory
Azure Data Factory
An Azure service for ingesting, preparing, and transforming data at scale.
9,487 questions
{count} votes

4 answers

Sort by: Most helpful
  1. Nasreen Akter 10,736 Reputation points
    2021-03-15T14:57:28.593+00:00

    Hi @Abhishek Vyas ,

    Hope you are looking for something like

    iif(!isNull(toString(byName('Address1'))) && !isNull(toString(byName('Address2'))) && !isNull(toString(byName('LineAddress3'))),  
        concat(iifNull(toString(byName('Address1')), ''), iifNull(toString(byName('Address2')), ''), iifNull(toString(byName('LineAddress3')), '')),   
        iif(!isNull(toString(byName('Address2'))) && !isNull(toString(byName('Address1'))) && !isNull(toString(byName('City'))),  
            concat(iifNull(toString(byName('Address2')), ''), iifNull(toString(byName('Address1')), ''), iifNull(toString(byName('City')), '')),   
            iif(!isNull(toString(byName('City'))) && !isNull(toString(byName('Address2'))),   
                concat(iifNull(toString(byName('City')), ''), iifNull(toString(byName('Address2')), '')),   
                ''  
            )  
        )  
    )  
    

    77866-img23.jpg

    Thanks! :)

    0 comments No comments

  2. Abhishek Vyas 101 Reputation points
    2021-03-15T15:06:44.963+00:00

    @Nasreen Akter . The solution is not dynamic in nature. Column names are dynamic.


  3. MartinJaffer-MSFT 26,011 Reputation points
    2021-03-31T23:36:17.767+00:00

    @Abhishek Vyas

    If all the colums are strings, you can use

    byNames($myColumnNames)  
    

    Otherwise it gets more complicated.

    reduce(array(byNames($columnames)),'',concat(#acc,toString(#item)),#result)
    
    0 comments No comments

  4. Jaganathan, NK. (Naveen Kumar) 0 Reputation points
    2023-09-08T17:27:46.2433333+00:00

    Hi,

    I want to improvise the requirement, consider before i perform the column concatenation, i want to perform the trim on each column. Below solution will not be sufficient.

    concat(toString(columns()))

    Thanks,

    Naveen

    0 comments No comments