Blog

Pivot, Unpivot, Transpose and Find and Replace in Data Prep

Pivot: turn a long table into a wide one

A sales export usually arrives long: one row per region and quarter, with the amount in a third column. The report people want is wide, with a column per quarter. Until now that meant opening the file in spreadsheet software and building a pivot table. The new Pivot step in Data Prep does it in the browser: choose the columns to group rows by (Region), the column whose values become the new headers (Quarter), and how to fill each cell: a count of the rows, or the sum, average, minimum, maximum, first, or last value of a number column.

RegionQuarterSales
EastQ1120
EastQ180
EastQ2150
WestQ190
WestQ2210
WestQ240

Grouped by Region, with columns from Quarter and the sum of Sales, those six rows become two:

RegionQ1Q2
East200150
West90250
The Pivot step in Data Prep, grouping sales rows by region with a column per quarter and the sum of sales in each cell
The Pivot step: group rows by Region, create columns from Quarter, and sum the Sales.

Turn on Sort columns A to Z to put the new columns in order and Ignore blank cells to leave empty cells out of the aggregation. With no group-by column, everything lands in one row, which is a quick way to get a total per quarter.

Unpivot: turn columns back into rows

Unpivot is the reverse. A budget with one column per month, or a survey with one column per question, becomes a long table with a key column that holds the old header and a value column that holds the cell. The columns you keep (an id, a name) are copied onto every new row, and Skip empty cells leaves out the rows that would hold nothing.

You check the columns to keep rather than the columns to unpivot, on purpose: in a saved template, a file that gains a new month column next year still unpivots correctly, as long as at least one column is kept.

Transpose: swap rows and columns

Transpose flips the whole table: each row becomes a column and each column becomes a row. Pick the column whose values become the new headers (a product code, a year) and name the key column that will hold the current column names. It suits small summary tables and the key-value exports some systems produce with one record per column.

Find and Replace across a whole file

Find and Replace changes text in every column or only in the ones you check. Type what to find and what to put in its place, or leave the replacement blank to remove the text. Three toggles cover the usual cases: Match case so Apple does not match apple, Whole word so cat does not match category, and Regular expression for patterns, with captured groups reused in the replacement as $1, $2 and so on.

The Find and Replace step in Data Prep with the Find field, the Replace with field, the Match case, Whole word and Regular expression toggles, and the list of columns to search
Find and Replace: whole-word matching, limited to the columns you check.

Numbers, dates, and true/false values keep their type when the result is still valid (changing 1,200 to 1200 keeps a number) and become text otherwise. A cell that ends up empty is treated as blank, so Remove Blank Rows can drop it in the next step. Each Find and Replace is its own step in the history, so applying a second pair adds a step instead of replacing the first.

Where the new steps live

  1. Open Data Prep, or upload a file on any converter page, which opens the same preview.
  2. Pick the step in the Tools sidebar: Find and Replace under Transform, and Pivot, Unpivot, and Transpose under Aggregate.
  3. Fill in the options and click Apply. The preview updates, the step joins the history, and Undo takes it back.
  4. Download the result as Excel, CSV, JSON, Parquet, or any other target, or save the steps as a template to run again on the next file.

Every source format works, because Data Prep reads the same datasets the converters do: a CAMT.053 statement, a Peppol invoice, or a PDF table can be pivoted like a CSV.

GS1 GDSN product data as spreadsheets

GS1 GDSN (Global Data Synchronisation Network) is how suppliers publish product data to retailers and distributors through certified data pools. A catalogue item notification describes every GTIN in a packaging hierarchy, from the pallet down to the case and the base unit, in deeply nested XML. GDSN to Excel reads GDSN 3 notifications one dataset at a time: the message header; the trade items, with one row for every GTIN at every packaging level and its parent GTIN, descriptor, description, measurements and dates; the descriptions in every language; the additional identifiers of each GTIN, such as a supplier-assigned number or a manufacturer part number, each with its type; the product characteristics with their value and unit; the referenced files such as images and safety data sheets; the dangerous goods with their UN number, hazard class and packing group; and the packaging hierarchy, one row per parent and child GTIN with its quantity.

The trade items are used when you do not pick a dataset. This is the part of a notification that becomes one of their rows, shortened:

<tradeItem>
  <gtin>10614141005120</gtin>
  <tradeItemUnitDescriptorCode>CASE</tradeItemUnitDescriptorCode>
  <nextLowerLevelTradeItemInformation>
    <quantityOfChildren>1</quantityOfChildren>
    <childTradeItem><gtin>00614141005123</gtin></childTradeItem>
  </nextLowerLevelTradeItemInformation>
  <tradeItemInformation>
    <extension>
      <trade_item_description:tradeItemDescriptionModule>
        <tradeItemDescriptionInformation>
          <brandNameInformation>
            <brandName>Northbridge</brandName>
          </brandNameInformation>
          <descriptionShort languageCode="en">HEX BOLT M10X50 A2 CASE</descriptionShort>
        </tradeItemDescriptionInformation>
      </trade_item_description:tradeItemDescriptionModule>
      <trade_item_measurements:tradeItemMeasurementsModule>
        <tradeItemMeasurements>
          <tradeItemWeight>
            <grossWeight measurementUnitCode="KGM">12.4</grossWeight>
          </tradeItemWeight>
        </tradeItemMeasurements>
      </trade_item_measurements:tradeItemMeasurementsModule>
    </extension>
  </tradeItemInformation>
</tradeItem>
A GS1 GDSN catalogue item notification opened on the GDSN to Excel page, showing the trade items dataset with one row per GTIN and packaging level
The trade items of a GDSN notification, one row per GTIN, from the pallet down to the base unit.

Measurements, weights, quantities and dates are typed, so a column of gross weights sums in Excel without cleanup. GDSN joins BMEcat, ETIM xChange and PIES among the product catalog formats added this fall.

Smaller changes

  • CFDI invoices have a new Tax totals dataset: one row per tax and rate (IVA 16%, IEPS, ISR and IVA withheld) with its base and amount, added up from the line items. Payment receipts show the totals they state, in MXN.
  • SAP OCI carts saved as Windows-1252 pages or logs are read with their accents intact, and a cart with more than 10,000 items is refused with a message that says so.
  • Batch results download as batch-results-<date>-<time>-<id>.zip, stamped with the time the batch was created, so a folder of downloads sorts itself.

Common questions

Can Pivot use a text column as the value? Yes, with the first, last, or count aggregations. Sum, average, minimum, and maximum need a number column.

How many columns can Pivot create? The step has a fixed cap on new columns to keep the preview and the download responsive. If a column has more distinct values than that, group or filter the rows first, or pivot on a different column.

Does Find and Replace work on numbers and dates? It matches against the text you see in the cell. When the result is still a valid number, date, or true/false value the type is kept; otherwise the cell becomes text.

Can the steps run on more than one file? Save the steps as a template, then apply it to the next upload, run it through the API, or use it in a batch on a paid monthly plan.

Where is the full list of changes? The What's New page lists every change with its date; last month's nine new formats post covers the bank statement, e-invoice and SAP formats. New posts appear in the RSS feed.