Forum Discussion

davidz106's avatar
davidz106
Helper III
4 years ago
Solved

Get data from folder and append

I hava a complicated .csv that I managed to format as I wish with 20 line of M code.   Is it possible to tell Power BI to watch a folder for new .csv then apply same query on it and only then appen...
  • rohit_singh's avatar
    4 years ago

    Hi davidz106 ,

    This can be done using a custom function in power query. You will need to create a custom function that contains your 20 line M code. 
    Please try to create your solution using the following steps as a guide :

    1) Load all csv files from folder

     

    2) Open a blank query and create a function as shown below :

    3) In the CSV query, remove extra columns. Then invoke the custom function 

    4) Select the custom function and the column. 

     

    What you are doing is taking each file in your staging location and feeding that as an input to your custom function using the file_path variable within the function. The output of the function is transformed data as per your M-code. The transformed data for each file will be added as a column after function invocation. Each row will have transformed data which you can then combine in additional steps.

    Hope this helps.

    Kind regards,

    Rohit


    Please mark this answer as the solution if it resolves your issue.
    Appreciate your kudos! 🙂