How to transform a multi-row excel table into single row

Anonymous
2023-03-30T07:08:46+00:00

Hi there

Ive spent some time searching on excel but could find an example of this situation.. I came across Power Query also, which looks quiet powerful, but that is a new tool to me that will take some time to pick up...

I have a table extracted from a PDF file which has multiple rows per ID (cols A to I) . I need to create a csv file with a single row per ID, with a column for each combination of ParameterName (Col B) and Column Headings (C to I)..

I realise I can do some transforming with concatenate formulas, but is there a better way?

There will be about 500 PDFs to extract (one per ID). The structure of the source table extracted will always be the same, so it would be great if I could automate the extractions from a folder with the pdfs, and then save the output in a separate csv file for each extracted table.....

The screen shot attached has a small sample of the output Im looking for... eg. columns A, B and C from the source table are transformed...

Best regards

David

Microsoft 365 and Office | Excel | For education | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments
{count} votes
Answer accepted by question author
  1. riny 20,530 Reputation points Volunteer Moderator
    2023-03-31T04:13:54+00:00

    The query below will transfer the table into the desired format. It's done solely by clicking in the user interface. No manual M-coding needed. Note that "Table1" refers to the data in the Source sheet.

    let Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],#"Replaced value" = Table.ReplaceValue(Source, null, 0, Replacer.ReplaceValue, {"pred", "LLN", "Pre-Best", "Pre-Z-Score", "Post-Best", "Post-Z-Score", "%Chg"}),#"Unpivoted other columns" = Table.UnpivotOtherColumns(#"Replaced value", {"ID", "ParameterName"}, "Attribute", "Value"),#"Added index" = Table.AddIndexColumn(#"Unpivoted other columns", "Index", 0, 1, Int64.Type),#"Inserted modulo" = Table.AddColumn(#"Added index", "Modulo", each Number.Mod([Index], 7), Int64.Type),#"Sorted rows" = Table.Sort(#"Inserted modulo", {{"Modulo", Order.Ascending}, {"Index", Order.Ascending}}),#"Inserted merged column" = Table.AddColumn(#"Sorted rows", "Merged", each Text.Combine({[Attribute], Text.From([ParameterName])}, "_"), type text),#"Choose columns" = Table.SelectColumns(#"Inserted merged column", {"ID", "Value", "Merged"}),#"Pivoted column" = Table.Pivot(Table.TransformColumnTypes(#"Choose columns", {{"Merged", type text}}), List.Distinct(Table.TransformColumnTypes(#"Choose columns", {{"Merged", type text}})[Merged]), "Merged", "Value")in#"Pivoted column"

    1 person found this answer helpful.
    0 comments No comments
Answer accepted by question author
  1. Ashish Mathur 101K Reputation points Volunteer Moderator
    2023-03-31T03:52:29+00:00

    Hi,

    You may download my solution workbook from here. Add data by rows/columns to the "Source" worksheet and click on Data > Refresh All. The updated result will be available on the "Query Editor solution" worksheet.

    Hope this helps.

    1 person found this answer helpful.
    0 comments No comments

8 additional answers

Sort by: Most helpful
  1. Anonymous
    2023-03-31T02:40:04+00:00

    Hi Ashish..

    Thank you for looking at this.... I have a shared a sample xslx file on onedrive

    tableExample.xlsx

    best regards

    David

    0 comments No comments
  2. Anonymous
    2023-03-31T06:07:28+00:00

    Thanks Ashish.. this is great!

    0 comments No comments
  3. Anonymous
    2023-03-31T06:18:48+00:00

    Thanks Riny... This worked too. I was able to just paste it into advanced editor ....

    0 comments No comments