Pivot Table Issues

How to Pivot Poorly Structured Excel Data Using LAMBDA and PIVOTBY

Kushani NimanthikaKushani Nimanthika Nov 10, 2026 869 views

Question details

The user needs to normalize and restructure dataset rows containing multiple delimited categories, correctly allocate value amounts, and summarize the data using dynamic array formulas.

How to Pivot Poorly Structured Excel Data Using LAMBDA and PIVOTBY
Product
Spreadsheets
Device & OS
not provided
Scenario
Transforming rows with grouped or delimited text categories into a properly expanded dataset, apportioning values across the new rows, and generating a pivot table automatically with modern array formulas.
Observed behavior
The original dataset is improperly structured with multiple categories merged into single rows, which prevents direct pivoting without a complex transformation pipeline to expand rows and apportion values.
Before you start

Ensure your spreadsheet software is updated to support modern dynamic array functions like LAMBDA and PIVOTBY, or be prepared to use standard data cleaning tools like Text to Columns as an alternative.

Solution 1Recommended

Use TOCOL and LAMBDA for Dynamic Data Normalization

Build a dynamic array formula using LET, LAMBDA, and TOCOL to unpivot delimited strings, expand corresponding rows, and pass the normalized data directly into PIVOTBY.

This approach avoids complex iterative row-by-row functions by unpivoting the entire table at once. It calculates the number of categories per row, splits them, and divides the amounts equally before feeding everything into the PIVOTBY function.

1
Define category counts

Use the LET function to define variables. Start by calculating the number of items in the delimited category string using LEN and SUBSTITUTE to count the delimiters.

2
Extract individual categories

Split the delimited strings into an array using TEXTBEFORE, TEXTAFTER, and SEQUENCE functions to separate each item.

3
Create a LAMBDA helper

Define a custom LAMBDA function within your LET statement to broadcast the other columns (like Region or Order Date) using TOCOL, ensuring they match the new expanded category rows.

4
Apportion numerical values

Divide your original values (e.g., Amount) by the category count calculated in step 1 to allocate the totals correctly across the new rows.

5
Wrap in PIVOTBY

Nest the normalized arrays inside the PIVOTBY function. Specify your expanded row fields, column fields, the apportioned values array, and the aggregation method (e.g., SUM).

Use TOCOL and LAMBDA for Dynamic Data Normalization
Formula Complexity: Modern array formulas can become highly complex. Ensure you balance mathematical precision with readability by clearly naming variables within the LET function.
Powerful Data Tools in WPS

Easily Normalize and Pivot Data in WPS Spreadsheet

WPS Spreadsheet provides powerful data transformation tools, robust dynamic array support, and intuitive PivotTables to help you handle poorly structured datasets without complex coding.

  1. 1. Open your dataset: Launch WPS Spreadsheet and open the workbook containing your poorly structured data.
  2. 2. Clean and normalize the data: Highlight your data and use the built-in Text to Columns feature under the Data tab to split merged categories, then copy down the corresponding row data.
  3. 3. Apportion values: Create a simple helper column to divide your row totals by the number of new categories to ensure accurate data allocations.
  4. 4. Insert a PivotTable: Select your newly structured data range, navigate to the Insert tab on the ribbon, click PivotTable, and drag your fields into the Rows, Columns, and Values areas.
Full compatibility with Microsoft Excel (.xlsx) formats and standard array functions.Intuitive Data menu tools like Text to Columns for fast and easy data cleaning.Advanced PivotTable features to quickly summarize normalized data natively.Lightweight software that processes large datasets and complex formulas smoothly.
microsoft office alternative - wps office

Frequently Asked Questions

What is the PIVOTBY function used for?

PIVOTBY is a modern dynamic array function that allows you to create pivot table-like data summaries directly within a formula using arrays, eliminating the need to insert a traditional PivotTable object.

How does the LAMBDA function help with poorly structured data?

The LAMBDA function lets you create custom, reusable functions directly within a cell. When cleaning data, it can modularize complex row-by-row tasks like expanding delimited strings, making your formulas easier to read, test, and maintain.

Why do I need to apportion amounts when unpivoting categories?

If a single row contains a total amount (e.g., $100) but applies to multiple categories, failing to apportion it will duplicate the $100 across the newly expanded rows, falsely inflating your grand total. Dividing the amount by the category count ensures reporting accuracy.

Can I normalize data without using complex dynamic arrays?

Yes. If you prefer not to use LET, LAMBDA, and PIVOTBY formulas, you can achieve the exact same result by using Power Query to split columns by delimiter into rows, or by using standard Text to Columns and manually unpivoting the data.