Power QueryExercises

Product code parsing

A clothing catalogue whose codes pack style, colour and size into one text value, and whose descriptions hide a pack size.

beginner · Skills: Split column by delimiter, Missing parts become null, Extract text between delimiters · Updated 2026-11-04

Data files

Queries

Validated in the Power Query Exercises simulator against the files above. Paste them into Excel or Power BI yourself; the header comments explain each source binding.

Style, colour, size and pack parsed-codes.pq

Download .pq

Split codes into parts and read the pack size from the description. Returns 10 rows: Style, Colour, Size, Description, Price, PackOf.

// Style, colour, size and pack
// Pack: Product code parsing (Power Query Exercises, https://powerqueryexercises.com/downloads/product-code-parsing)
//
// Source bindings
// In the Power Query Exercises simulator each name below is bound directly to a pack file. In Excel or
// Power BI Desktop the first steps of this query do that binding instead:
//   Catalog        the pack file catalog.csv -> File.Contents(PackFolder & "catalog.csv")
// Set PackFolder to the folder where you extracted the pack (keep the trailing backslash).
//
// Validated in the Power Query Exercises simulator (engine 0.1.0) against this pack's files; it returns
// 10 rows with columns Style, Colour, Size, Description, Price, PackOf.
// It has not been run in Excel or Power BI by us. This is query text, not a ready-to-refresh workbook.
// Independent practice material; not affiliated with or endorsed by Microsoft.
let
    PackFolder = "C:\PQE\product-code-parsing\",
    Catalog = File.Contents(PackFolder & "catalog.csv"),
Source = Table.PromoteHeaders(Csv.Document(Catalog, [Delimiter=",", Encoding=65001, QuoteStyle=QuoteStyle.Csv]), [PromoteAllScalars=true]),
    #"Split" = Table.SplitColumn(Source, "Code", Splitter.SplitTextByDelimiter("-"), {"Style", "Colour", "Size"}),
    #"Pack" = Table.AddColumn(#"Split", "PackOf", each if Text.Contains([Description], "pack of ") then Number.From(Text.AfterDelimiter([Description], "pack of ")) else 1, Int64.Type),
    #"Changed Type" = Table.TransformColumnTypes(#"Pack", {{"Price", type number}})
in
    #"Changed Type"

Follow along in a host

Follow along in Excel

  1. Download the pack and extract the zip, for example to C:\PQE\<pack name>\.
  2. In Excel (Microsoft 365 or 2016+ on Windows), go to Data → Get Data → From Other Sources → Blank Query.
  3. In the Power Query Editor choose Home → Advanced Editor, select everything and paste the contents of the .pq file.
  4. Change the PackFolder line to the folder you extracted to, then choose Done.
  5. If Excel asks about privacy levels or file access, allow access to that folder. Then choose Home → Close & Load.

Follow along in Power BI Desktop

  1. Download the pack and extract the zip.
  2. In Power BI Desktop choose Home → Transform data to open the Power Query Editor, then Home → New Source → Blank Query.
  3. Choose Home → Advanced Editor, paste the contents of the .pq file and change the PackFolder line to your folder.
  4. Choose Done, check the preview against the expected rows in the query header, then Close & Apply.

Then try this

  1. Look at CAP-RED and BAG-OLIVE: Size is null, not an error, because the split asks for three parts.
  2. Add a code with four parts (e.g. TEE-NAVY-L-TALL) and see what happens to the extra part.

Related lessons

Original fictional data, free to use for learning and teaching. Power Query Exercises is not affiliated with or endorsed by Microsoft.