mergecolumn

Combine fields from different columns into a single column.

This guide explains how to configure the mergecolumn instruction. To learn about another instruction, go back to the Available custom script instructions overview.

Introduction

Use the mergecolumn instruction to combine different columns in a data extract into a single column. The combined values are stored in a JSON-style dictionary. The name of the column is stored as the dictionary key, and the value within the column is stored as the dictionary value.

Creating a custom script transformation using the mergecolumn instruction

To create and configure a custom script using the mergecolumn instruction, follow these steps:

  1. Create a custom script transformation.

  2. In the Instructions step, select the mergecolumn instruction.

  3. To configure the custom script instruction, fill in the following fields. Required fields are marked with an asterisk (*).

Fieldname*

Enter the name of the new column that contains the merged values.

Columns

Enter the names of the columns to combine into one column. Click to add the names of more columns to combine. If you select this option, the All and Prefix fields are disabled.

All

Select this option if you want to merge all the columns within a table into a single column. If you select this option, the Columns and Prefix fields are disabled.

Prefix

Enter the start of the names of the columns to merge. For example, enter Ad_ into prefix and only the column names that start with Ad_ are included in the merge transformation.

The names of the columns in the final merged data extract are renamed and the entered prefix is removed. For example, a Prefix of Ad_ would rename Ad_Clicks to Clicks.

If you select this option, the Columns and All fields are disabled.

Include

Enter the names of fields to be merged.

Exclude

Enter the names of the columns to be excluded from the merge. Use this option if you have selected the All option.

Drop

Select this option to remove the original columns from the data extract. If selected, the original columns will remain in the data extract along with the merged columns.

Serializer

Select the format in which the merged values are stored. Currently, the only option is JSON.

Example

Transformation configuration

Fieldname*

Ad Group Clicks

Columns

  • Ad_Groups

  • Ad_Clicks

Drop

Select this checkbox.

Serializer

JSON

Data table before transformation

Campaign

Ad_Group

Ad_Clicks

Brand

media

7

Brand

ecommerce

3

Dashboard

media|social

18

Data table after transformation

Campaign

Ad Group Clicks

Brand

{"Ad Group":"media", "Clicks":"7"}

Brand

{"Ad Group":"ecommerce", "Clicks":"3"}

Dashboard

{"Ad Group":"media|social", "Clicks":"18"}