Forum Discussion

POJ's avatar
POJ
Copper Contributor
Aug 30, 2025

Extracting data from a matrix

I have a matrix containing 4348 values distributed in a matrix
Most of the cells in the matrix contians no values (are empty)
Some cells contains values which I want to extract.
The problem is how  can I sort the matrix so that each value is combined with year and depth in the same line.
I have tried to solve the problem using a Pivot table in Excel Office 2010, in vain. 

The first figure shows the data matrix:

The second figure below shows the wanted solution:

In advance:

Thank you for your help 

 

4 Replies

  • Harun24HR's avatar
    Harun24HR
    Bronze Contributor

    For Excel-2010 it will need few of a helper column or VBA or Power Query approach. For Microsoft Excel 365 here is a formula approach.

    =REDUCE({"Year","Depth","Value"},TOCOL(B1:D1&"|"&A2:A4&"|"&B2:D4),LAMBDA(a,x,VSTACK(a,TEXTSPLIT(x,"|"))))

     

  • peiyezhu's avatar
    peiyezhu
    Bronze Contributor

    https://learn.microsoft.com/en-us/answers/questions/5336745/transposing-one-row-into-multiple-rows?forum=msoffice-all&referrer=answers

  • Concept like this:

     

    1. Install Power Query Add-In

    2. Load Your Matrix into Power Query
      • Select your matrix and go to Power Query > From Table
      • Make sure your matrix has headers (e.g. years) and row labels (e.g. depts)
    3. Unpivot the Data
      • Select the column containing depths
      • Right-click and choose Unpivot Other Columns
      • Dept
      • Attribute (year)
      • Value
      • In Power Query:
      • This will convert your matrix into a table with:
    4. Rename Columns
      • Rename “Attribute” to “Year”
      • Rename “Value” to “Measurement” or whatever fits your context
    5. Filter Out Empty Values
      • Use the filter dropdown on the “Value” column to remove null or empty cells
    6. Load the Clean Table Back to Excel
      • Click Close & Load to insert the cleaned table into a new sheet
    • POJ's avatar
      POJ
      Copper Contributor

      Power Query worked well

      Thank you for your help.

      Kind Regards

      POJ

Resources