Forum Discussion

Sumit_Bhokare's avatar
Sumit_Bhokare
Brass Contributor
Dec 15, 2023
Solved

How to combine multiple excel data using power query

All, I have multiple excel files in single folder which have same form however within headers there is some additional spaces at start or end in few excel sheets of workbook. when I tried to combine those in power query data from all excel is not getting transformed. Getting error for few excel sheets which have additional spaces.

 

Can any one suggest solution for those excel sheets which have spaces at start or end?

 

Thank you!

Sumit

  • Lorenzo's avatar
    Lorenzo
    Silver Contributor

    Hi Sumit_Bhokare 

     

    however within headers there is some additional spaces at start or end in few excel sheets

     

    Below is a simulation. Not obvious but Sheet2 headers are: ' abc '; 'def '; ' ghi '


    What you need to do, after Promoting Headers on each sheet, is to add a step (with the Advanced Editor) to Trim the header names (Table.TransformColumnNames). Example with above Sheet1:

    let
        Source = Excel.CurrentWorkbook(){[Name="Sheet1"]}[Content],
        PromotedHeaders = Table.PromoteHeaders(Source, [PromoteAllScalars=true]),
        TrimmedHeaders = Table.TransformColumnNames(PromotedHeaders, Text.Trim)
    in
        TrimmedHeaders

    then you combine your sheets

     

    Re. Getting error for few excel sheets which have additional spaces

    Sorry but this means nothing/doesn't help if you don't post the corresponding error message

    • Sumit_Bhokare's avatar
      Sumit_Bhokare
      Brass Contributor

      Lorenzo 

      refer below snapshot of error message.

      test1 file have single worksheet with name as sheet however remaining files have multiple worksheets like 2 or 3 but they all have different names.

      Do we need to match worksheet name as well?

       

       

Resources