# Data Mapping cfxdm - dm:mergecolumns

**dm:mergecolumns:** This cfxdm function allows the user to select multiple columns using include or exclude columns options using a regular expression format and merge them into a single target column.

**dm:mergecolumns** synta&#x78;**:**&#x20;

* **include (**&#x4D;andator&#x79;**):** Specify a column or columns in regular expression format to include matched columns.
* **exclude (**&#x4F;ptiona&#x6C;**):** Specify a column or columns in regular expression format to exclude matched columns.
* **to** (Mandatory): Target column for merged data from selected one or more columns.

{% hint style="info" %}
**Note:** After merging multiple columns into a single column, it will remove source columns from the final output.
{% endhint %}

### Example 1:

Step 1: Create an empty **dm\_mergecolumns\_example\_1** using AIOps studio as shown in the below screenshot.

![Empty pipeline](https://2978683539-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LhoMVYxiQlKXh6OxX98%2F-MfdP7qFnFsnzVYfyo5E%2F-MfdQeH9N-PNbmLEB-2R%2FScreen%20Shot%202021-07-27%20at%2012.26.16%20PM.png?alt=media\&token=f5150976-c878-4b32-88f4-50c6bc0cbc46)

Step 2: Add the following pipeline code/commands into the above-created pipeline as shown in the below screenshot:

You can copy the below code into your pipeline and execute that in your environment.\
\
\&#xNAN;*`##### This pipeline creates a set of records/dateset details coming from a netflow`*  \
*`##### environment.`* \
\
*`##### This dataset includes flow.client_addr, flow.server_addr, flow.service_port as`* \
*`##### source columns. This pipeline uses dm mergecolumns to merge the source columns`*\
*`##### to a single target column`*\
\
*`@dm:empty`* \
*`--> @dm:addrow flow.client_addr = '10.95.133.42' & flow.server_addr = '10.95.133.40' & flow.service_port = '9092'`* \
*`--> @dm:addrow flow.client_addr = '10.95.122.170' & flow.server_addr = '10.95.122.169' & flow.service_port = '9092'`*\
&#x20;*`--> @dm:addrow flow.client_addr = '10.95.122.170' & flow.server_addr = '10.95.122.169' & flow.service_port = '9092'`* \
*`--> @dm:addrow flow.client_addr = '10.95.122.170' & flow.server_addr = '10.95.122.169' & flow.service_port = '9092'`* \
*`--> @dm:addrow flow.client_addr = '10.95.122.205' & flow.server_addr = '10.95.122.212' & flow.service_port = '9300'`* \
*`--> @dm:addrow flow.client_addr = '10.95.117.35' & flow.server_addr = '10.95.117/37' & flow.service_port = '686'`* \
*`--> @dm:addrow flow.client_addr = '10.95.122.105' & flow.server_addr = '10.95.122.212' & flow.service_port = '443'`* \
*`--> @dm:addrow flow.client_addr = '10.95.122.105' & flow.server_addr = '10.95.122.212' & flow.service_port = '9300'`* \
*`--> @dm:addrow flow.client_addr = '10.95.122.121' & flow.server_addr = '10.95.122.212' & flow.service_port = '9092'`*\
&#x20;*`--> @dm:addrow flow.client_addr = '10.95.122.109' & flow.server_addr = '10.95.122.212' & flow.service_port = '8443'`*\
\
*`--> @dm:mergecolumns include = 'flow.client_addr|flow.server_addr|flow.service_port' & to = 'flow.unique_id'`*

![Pipeline code added ](https://2978683539-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LhoMVYxiQlKXh6OxX98%2F-MfdSThgco9zxR7_tdfa%2F-MfdTUON3zg-U4hKagDY%2Fimage.png?alt=media\&token=4ea3f210-ffd9-457d-9fdc-faeb118bc00e)

Step 3: Click verify button to make sure syntax and pipeline code is correct (as shown below)

![Pipeline code is verified using 'Verify' button as shown above](https://2978683539-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LhoMVYxiQlKXh6OxX98%2F-MfdTajhVXuQrUU_fngK%2F-MfdUAf7fgtuti5sJMnd%2FScreen%20Shot%202021-07-27%20at%2012.41.37%20PM.png?alt=media\&token=b1699cf5-cb81-479f-b39e-4f963c422a89)

Step 4: Click execute button and execute the pipeline. RDA will execute the pipeline without any errors (as shown below).

![Screenshot -1 ](https://2978683539-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LhoMVYxiQlKXh6OxX98%2F-MfdUIXzrNMkXSX4rSqq%2F-MfdUhzIbiduUZxTVPCx%2Fimage.png?alt=media\&token=22a7c1c7-048c-41a6-8aa5-9f0135aaa222)

![Screenshot - 2 (successful execution of pipeline)](https://2978683539-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LhoMVYxiQlKXh6OxX98%2F-MfdUyasoYQm38fLUbeG%2F-MfdVWY2kHRPoBeGvmKv%2FScreen%20Shot%202021-07-27%20at%2012.47.27%20PM.png?alt=media\&token=9dbaa26b-0301-4fda-b020-b63fb23cfb54)

Step 5: RDA uses the dm mergecolumns function to merge the specified columns into target column and prints the resultant output as shown in the following screenshot.

![Three columns are merged into single target column as shown in the above screenshot.](https://2978683539-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-LhoMVYxiQlKXh6OxX98%2F-MfdVxcd7bGIhX1H8oLk%2F-MfdWQVKwuw-KnR_4erd%2FScreen%20Shot%202021-07-27%20at%2012.51.27%20PM.png?alt=media\&token=338a2a75-5764-4dd3-9715-673871351fd4)

dm: merge functionality will be very useful when uniqueness is needed from within the dataset by combining couple of columns into one column as a key.
