0088 Dynamic Pivot

A practical Advanced ETL Processor example for building, testing, and adapting one automation workflow.

Advanced ETL Processor
4.9 ★★★★★ Based on 16 reviews on Capterra See all reviews on Capterra →

Use this example to build one working automation package, test it safely, and then adapt it to your own files, folders, or data rules. Start small. Automation is helpful; automated mistakes are just faster mistakes.

Customer question

Question from the customer

Is it possible to make a pivot with dynamic fields?

I have a table with supplier material, delivery date, and quantity. The delivery dates are not fixed, so a fixed pivot allocation is not practical.

Can I make a pivot when the list of dates changes from file to file?

Original forum post

Data example

source example

Desired output

desired output

Answer

Yes, but not with the standard Pivot transformation when the number of dates is unknown. Build the header dynamically, build the matching quantity lists, then combine them. Dynamic pivots are useful because source systems rarely ask politely before changing the columns.

solution

How it works

  1. Create a sorted list of dates delimited by comma. This becomes the header.
  2. For every supplier material, create a comma-delimited list of quantities sorted by date, filling gaps with zeros.
  3. Combine the header and sales rows.

Additional writers are included to make the example easier to understand. They can be deleted except for the final result writer.

Creating the header

The SHIP_DATE field is reformatted, deduplicated, and sorted. Then the <Header> variable is populated using the Accumulate Strings transformation function.

Transformation

creating header 1

Transformation result

creating header 2

Creating QTY lists

Data is joined with a list of dates.

sales list 1

Data is deduplicated and the QTY list is created.

sales list 2

Data is grouped by SUPPLIER_MAT and the last value of the QTY list.

sales list 3

Calculating Data Field

When the row number equals 1, use the <Header> variable as the value. Otherwise, use SUPPLIER_MAT plus the QTY list.

calculating header

Transformation result

result

To view the example follow the steps below

  • Download and install Advanced ETL Processor [Link]
  • Download and unzip the example [Link]
  • Create a new transformation and open the .ats file
  • Double-click the Reader object and amend the source file path
  • Double-click the Writer objects and amend the source file path
  • Double-click the Sorter object and amend the source file path
  • Press the green arrow to run the transformation.

Related Advanced ETL Processor resources

For more automation examples, review the Advanced ETL Processor tutorials, read the WIKI, or download the Advanced ETL Processor Enterprise trial.