Forum Discussion

Alirezam's avatar
Alirezam
Icon for Helper V rankHelper V
6 years ago

Merging multiple csv files as importing to Power Bi

Hi mates,

I have got multiple csv files to be imported to Power Bi. They all have the same number of rows but different columns hence, need to be merged and not appended. When using the Power Bi default, the data are combined (appended) which I do not need. I need the data to sit across (merging) and come up with the same number of rows at the end. Any indication of how can I do this when I am importing the data from the source?

Regards,

6 Replies

  • v-alq-msft's avatar
    v-alq-msft
    Icon for Community Support rankCommunity Support

    Hi, Alirezam 

     

    As is said in the document , if you use folder connector to combine files, it will append multiple files that have the same schema, combine them into a single logical table. I'd like to suggest you use 'Text/CSV' connector to connect to CSV files. Then you may go to 'Home' ribbon, click 'Merge Queries', set as below.

     

    Finally you may expand the column 'File2' to get the result.

     

    Best Regards

    Allan

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

     

  • Did you know that behind the scenes both Append and Merge are served by the same Table.Combine statement?

     

    Just use Append and trust Power Query to sort out the columns. 

     

    HOWEVER: for this to work the spelling of the column names has to be consistent. Remember that M code is case sensitive.

     

    After the Table.Combine you want to use Table.SelectColumns  rather than Table.RemoveColumns, for hopefully obvious reasons.

    • Alirezam's avatar
      Alirezam
      Icon for Helper V rankHelper V

      Thanks for your reply.

      When we use 'combine' as you suggested, the files get appended and not merged. The column names are not consistent and should not be because I need to have them next to each other and not on the top of each other. Look below please: if you use append C1 will be on the top of D3 which does not make sense.

       

      File 1:

      Date                      C1C2

      4/12/2019

      56
      1/3/20191012

       

      File 2:

      Date                     D3D8

      4/12/2019

      46
      1/3/2019310

       

    • Alirezam's avatar
      Alirezam
      Icon for Helper V rankHelper V

      Thanks,

      My problem is not with the queries. My question was when you import the csv files. when you select the multiple csv files to import, the Combine option only append the files

  • v-alq-msft's avatar
    v-alq-msft
    Icon for Community Support rankCommunity Support

    Hi, Alirezam 

     

    If you take the answer of someone, please mark it as the solution to help the other members who have same problems find it more quickly. If not, let me know and I'll try to help you further. Thanks.

     

    Best Regards

    Allan