Converting Two-Dimensional Tables to Flat Lists Using Excel Formulas

📅 Oct 13, 2026 📝 Sarah Miller

Manually reshaping two-dimensional Excel matrices into flat, database-ready lists is a tedious, error-prone chore for data analysts. While traditional workflows rely on manual copying or launching Power Query, these standard methods often disrupt active modeling. Fortunately, modern dynamic array formulas grant immediate, real-time automation without leaving your workbook. As a brief stipulation, this technique requires Excel 365 to utilize advanced layout functions. For example, you can seamlessly convert a monthly cross-tabulated sales grid into a clean, three-column ledger. Below, we outline the exact nested formula construction to automate your data flattening.

Converting Two-Dimensional Tables to Flat Lists Using Excel Formulas

Excel Formula to Transpose Two-Dimensional Tables with Flat Lists

In data analysis, the structure of your data determines the ease of your workflow. Often, we encounter data in a two-dimensional (2D) table (also known as a matrix or crosstab). While 2D tables are excellent for human readability and quick manual entry, they are highly inefficient for data analysis tools like Pivot Tables, Power BI, or Python's Pandas. These systems require data in a normalized, flat list format (often referred to as unpivoting or flattening).

This article provides a comprehensive guide on how to use modern and traditional Excel formulas to transpose 2D tables into flat lists, as well as the reverse process: unflattening flat lists back into structured matrices.

Understanding the Transformation

Imagine you have a sales table where row headers represent Products, column headers represent Months, and the intersecting cells represent Sales Value. We want to transform this into a three-column database list:

  • Column 1: Product (Row Header)
  • Column 2: Month (Column Header)
  • Column 3: Sales (Data Value)

Method 1: The Modern Way (Excel 365)

With the release of Excel 365 and Excel 2021, dynamic arrays and helper functions like LET, TOCOL, and HSTACK have turned complex array math into elegant, readable formulas. Below is the ultimate formula to flatten any 2D grid into a flat table dynamically.

The Formula

=LET(
    row_headers, A2:A10,
    col_headers, B1:G1,
    data_grid, B2:G10,
    
    flat_rows, TOCOL(IF(SEQUENCE(1, COLUMNS(col_headers)), row_headers)),
    flat_cols, TOCOL(IF(SEQUENCE(ROWS(row_headers), 1), col_headers)),
    flat_vals, TOCOL(data_grid),
    
    result, HSTACK(flat_rows, flat_cols, flat_vals),
    FILTER(result, flat_vals <> "")
)

How It Works: Step-by-Step

  1. LET Function: This function defines variables (like row_headers, col_headers, and data_grid) to keep the formula organized, fast, and easy to edit.
  2. Generating Flat Rows (flat_rows): The formula IF(SEQUENCE(1, COLUMNS(col_headers)), row_headers) broadcasts (stretches) the vertical row headers across multiple columns to match the width of our data grid. Applying TOCOL then flattens this temporary matrix into a single vertical array, perfectly repeating each row header for every corresponding column.
  3. Generating Flat Columns (flat_cols): Similarly, IF(SEQUENCE(ROWS(row_headers), 1), col_headers) broadcasts the horizontal column headers down across rows, matching the height of our grid. TOCOL flattens this so that the column headers cycle sequentially.
  4. Flattening Data Values (flat_vals): The TOCOL(data_grid) function flattens the intersection values row-by-row into a single, continuous column.
  5. Combining and Filtering (HSTACK & FILTER): HSTACK merges the three flat arrays side-by-side. Finally, FILTER removes rows where the value is blank, ensuring a clean, compact database list.

Method 2: The Traditional Way (Excel 2019 and Older)

If you are working on legacy versions of Excel that do not support dynamic arrays or TOCOL, you can achieve the same result using index-matching mathematical logic. We will combine INDEX, INT, MOD, and ROW functions.

The Mathematical Logic

To pull from a 2D grid of size R (rows) by C (columns) using a single, incrementing row counter k (starting at 0):

  • Row Index in Grid: INT(k / C) + 1
  • Column Index in Grid: MOD(k, C) + 1

Implementation Formulas

Assuming your 2D table spans from A1 to G10 (where A2:A10 are Row Headers, B1:G1 are Column Headers, and B2:G10 are Values). In your flat list destination sheet, enter the following formulas on row 2 and drag them down:

1. Extracting Row Headers (e.g., in cell I2)

=INDEX($A$2:$A$10, INT((ROW(A1)-1)/COLUMNS($B$1:$G$1))+1)

2. Extracting Column Headers (e.g., in cell J2)

=INDEX($B$1:$G$1, MOD(ROW(A1)-1, COLUMNS($B$1:$G$1))+1)

3. Extracting Intersection Values (e.g., in cell K2)

=INDEX($B$2:$G$10, INT((ROW(A1)-1)/COLUMNS($B$1:$G$1))+1, MOD(ROW(A1)-1, COLUMNS($B$1:$G$1))+1)

Note: Drag these formulas down until they return an #REF! error, which indicates that you have successfully mapped all permutations of the table.


Method 3: Reverse Unflattening (Flat List to 2D Table)

What if you have a database flat list (Product, Month, Value) and want to generate a structured 2D table from scratch using dynamic array formulas? This is often referred to as "unflattening."

Let's assume your flat list is a structured table named FlatTable with columns: [Product], [Month], and [Sales].

Formula Location Formula Description
Row Headers (e.g., E2) =UNIQUE(FlatTable[Product]) Extracts a distinct vertical list of all products.
Column Headers (e.g., F1) =TRANSPOSE(UNIQUE(FlatTable[Month])) Extracts a distinct horizontal list of months.
Values Intersection (e.g., F2) =SUMIFS(FlatTable[Sales], FlatTable[Product], E2#, FlatTable[Month], F1#) Populates the whole matrix using the spill ranges (#).

By referencing E2# and F1#, the SUMIFS calculation automatically spills across both rows and columns to fill the entire matrix perfectly. If your data updates, the 2D matrix adjusts its dimensions dynamically.


Summary: Performance and Recommendations

When choosing a method to transpose your data, consider the size of your dataset and your Excel version:

  • For small to medium datasets (< 10,000 cells) in Excel 365: Use the modern LET and TOCOL formula. It's incredibly fast, clean, and requires no manual copy-paste actions.
  • For legacy systems (Excel 2019 and older): Use the INDEX, INT, and MOD math approach. It is reliable but can slow down your workbook if applied to tens of thousands of rows.
  • For very large enterprise datasets (> 50,000 cells): Excel formulas can become computationally expensive. In these scenarios, it is highly recommended to use Power Query. Simply select your table, go to Data > From Sheet, select the header columns, right-click, and select Unpivot Other Columns.

Mastering these formulas allows you to fluidly shift between readable presentation layouts and clean, normalized backend databases without ever leaving the formula bar.

Disclaimer:
The documents and templates provided on this page are for informational and illustrative purposes only. They do not constitute professional, legal, or financial advice, and should not be relied upon as such. Because individual circumstances and regulatory requirements vary, these materials may not be suitable for your specific needs. We recommend consulting with a qualified professional before adapting or using any of these examples for official or commercial purposes.