recast

Use duplicated values from a data extract to create a new header.

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

Introduction

Use the recast instruction to transpose distinct values in a column into a header. This transformation is the opposite of the melt instruction.

When configuring this transformation, select the name of the column that contains the distinct values to convert into a header. See the example below.

This transformation is often used to reverse the effects of the melt instruction.

Creating a custom script transformation using the recast instruction

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

  1. Create a custom script transformation.

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

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

Key*

Enter the name of the column that you do not want to be transposed into the header. To keep multiple columns as columns, click and enter the names of the columns you do not want to be transposed into the header.

Variablefield*

Enter the name of the column that contains the distinct values to transpose into the header.

Valuefield*

Enter the name of the column that contains the values used to populate the new columns. See the example below. If multiple values exist under a given key and variablefield, the transformation combines the multiples values into a list. You can configure how the list is formatting by entering a python expression in the Reducers field.

Samplesize

Enter the number of lines to search through to find the distinct values to use in the header.

Reducers

Enter a python expression used to format multiple values into a list.

Missing

Enter a string value to use if values cannot be transposed with the given variablefield or valuefield.

Subtable

Enter the name for a subtable that you want to use within this custom script.

A subtable is a temporary table that only exists for this custom script. You can apply additional instructions within the same custom script to the subtable. However, the subtable cannot be used in any other custom scripts.

If a subtable does not exist for the current custom script, the transformation is applied to the data extract, and the enriched data is output into the subtable. If the subtable already exists for the custom script, the subtable is used as the input for the transformation and optionally as the output.

Example

Transformation configuration

Key*

Campaign

Variablefield*

Transposed columns

Valuefield*

Transposed values

Data table before transformation

Campaign

Transposed columns

Transposed values

Brand

Ad Group

media

Brand

Clicks

7

Brand

Ad Group

ecommerce

Brand

Clicks

3

Dashboard

Ad Group

media|social

Dashboard

Clicks

18

Data table after transformation

Campaign

Ad Group

Clicks

Brand

media

7

Brand

ecommerce

3

Dashboard

media|social

18