Forum Discussion

PhillipB's avatar
PhillipB
Frequent Visitor
2 years ago
Solved

Combining files with column names only available after processing

I have got a folder of files with the following structure

 

Measurement limits

Part 1 xxxxx

Part 2 xxxxx

Part 3 xxxxxx

 

Measurement Results

Part      A  B  C  D

Part 1   1   2  3  4

Part 2   2   4  5  4

 

The headers in the results section will change, the second could be A B E F

I need to combine these files and have each of the Measurement Results as column headings.

  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi PhillipB 

     

    Assume that you have excel files like below in a folder, you can use Power Query Folder connector to connect to this folder. 

    After connection, you can combine files. It will let you select a file as sample file. 

    After combining files, it will generate and group queries into the following structure. Use Enter data feature to add a table "ColumnHeaders" which has all possible column headers and has 0 row data. Just like below. 

    In "Transform Sample File" query, filter out the top rows before Results section, promote first row to headers, remove the auto-generated "Changed Type" step, combine the earlier "ColumnHeaders" table to the result. Outcome:

    "Transform Sample File" code:

    let
        Source = Excel.Workbook(Parameter1, null, true),
        Tabelle1_Sheet = Source{[Item="Tabelle1",Kind="Sheet"]}[Data],
        #"Promoted Headers" = Table.PromoteHeaders(Tabelle1_Sheet, [PromoteAllScalars=true]),
        // Remove top rows before results section
        #"Filtered Rows" = Table.SelectRows(#"Promoted Headers", each ([Column2] <> null)),
        // Promote first row as column headers
        #"Promoted Headers1" = Table.PromoteHeaders(#"Filtered Rows", [PromoteAllScalars=true]),
        // Remove auto-generated "Changed type" step caused by "promote headers" step
        // Combine ColumnHeaders table to this query
        CombineColumnHeaders = Table.Combine({#"Promoted Headers1", ColumnHeaders})
    in
        CombineColumnHeaders

     

    In the combined query, remove the auto "Changed Type" column, then you will have all file results combined. 

     

    Best Regards,
    Jing
    If this post helps, please Accept it as Solution to help other members find it. Appreciate your Kudos!

2 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi PhillipB 

     

    Assume that you have excel files like below in a folder, you can use Power Query Folder connector to connect to this folder. 

    After connection, you can combine files. It will let you select a file as sample file. 

    After combining files, it will generate and group queries into the following structure. Use Enter data feature to add a table "ColumnHeaders" which has all possible column headers and has 0 row data. Just like below. 

    In "Transform Sample File" query, filter out the top rows before Results section, promote first row to headers, remove the auto-generated "Changed Type" step, combine the earlier "ColumnHeaders" table to the result. Outcome:

    "Transform Sample File" code:

    let
        Source = Excel.Workbook(Parameter1, null, true),
        Tabelle1_Sheet = Source{[Item="Tabelle1",Kind="Sheet"]}[Data],
        #"Promoted Headers" = Table.PromoteHeaders(Tabelle1_Sheet, [PromoteAllScalars=true]),
        // Remove top rows before results section
        #"Filtered Rows" = Table.SelectRows(#"Promoted Headers", each ([Column2] <> null)),
        // Promote first row as column headers
        #"Promoted Headers1" = Table.PromoteHeaders(#"Filtered Rows", [PromoteAllScalars=true]),
        // Remove auto-generated "Changed type" step caused by "promote headers" step
        // Combine ColumnHeaders table to this query
        CombineColumnHeaders = Table.Combine({#"Promoted Headers1", ColumnHeaders})
    in
        CombineColumnHeaders

     

    In the combined query, remove the auto "Changed Type" column, then you will have all file results combined. 

     

    Best Regards,
    Jing
    If this post helps, please Accept it as Solution to help other members find it. Appreciate your Kudos!