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.
{count} votes

5 answers

Sort by: Most helpful
  1. MartinJaffer-MSFT 26,161 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)
    
    1 person found this answer helpful.
    0 comments No comments

  2. Nasreen Akter 10,891 Reputation points Volunteer Moderator
    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

  3. 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.


  4. Anonymous
    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

  5. Mohammad Soori 0 Reputation points
    2024-05-27T10:02:06.73+00:00

    I used this command as a Derived Column, and it works fine for me:

    concatWS('~',toString(columns()))
    

    '~' is a delimiter.

    0 comments No comments

Your answer

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