Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

How to import two folders with different data

Hello,

 

I am struggling to get two folders imported which contain different types of CSVs.

 

When I add the second folder as source, the query editor shows the helper queries from the first folder and when I modify them, the first folders data gets messed up.

Here is, how my query editor looks like as an image.

 

I'd need a new "Transform File" and "Transform Sample File" function for the second folder but I don't know how to create it.

 

Can anyone point me in the right direction?

 

Zap.

  • the helper functions are very nice when you are new to Power Query and the M language.  Once your knowledge has increased you will find that they are rather ineffective and that they can be simplified a lot, and even can be eliminated in some cases.

     

    Two options:

    1. rename your existing helper function components for the first folder before creating the query for the second folder.

    2. Create a M function that does everything the helper functions do, but in a more elegant way.

     

    Example for 2:

     

     

    (Parameter) => let
            Source = Csv.Document(Parameter,[Delimiter=",", Encoding=65001, QuoteStyle=QuoteStyle.Csv]),
            #"Promoted Headers" = Table.PromoteHeaders(Source, [PromoteAllScalars=true]),
            Selected = Table.SelectColumns(#"Promoted Headers",Columns)
    in
        Selected

     

     (Note: "Columns" is a list of desired column - this is done to filter the source files early, and to avoid having to load the "Sample File" twice like the helper function does)

3 Replies

  • the helper functions are very nice when you are new to Power Query and the M language.  Once your knowledge has increased you will find that they are rather ineffective and that they can be simplified a lot, and even can be eliminated in some cases.

     

    Two options:

    1. rename your existing helper function components for the first folder before creating the query for the second folder.

    2. Create a M function that does everything the helper functions do, but in a more elegant way.

     

    Example for 2:

     

     

    (Parameter) => let
            Source = Csv.Document(Parameter,[Delimiter=",", Encoding=65001, QuoteStyle=QuoteStyle.Csv]),
            #"Promoted Headers" = Table.PromoteHeaders(Source, [PromoteAllScalars=true]),
            Selected = Table.SelectColumns(#"Promoted Headers",Columns)
    in
        Selected

     

     (Note: "Columns" is a list of desired column - this is done to filter the source files early, and to avoid having to load the "Sample File" twice like the helper function does)

    • Anonymous's avatar
      Anonymous
      Not applicable

      Thank you for your answer! I used the option to rename the functions which I didnt think of before (obviously) and afterwards it was pretty simple to add my second data source!

       

      Zap.

       

  • AllisonKennedy's avatar
    AllisonKennedy
    Icon for Community Champion rankCommunity Champion

    You should be able to use the Get Data > From Folder twice, and point to the two different folders, then do an append to combine them once they're both in the same format. 

     

    Otherwise see if this exercise helps you understand the helper queries a bit better: 

    Use Parameters to Combine Data