excelpowerpivot

How to reuse a set of power query steps in another Excel document?


We have 4GB csv file which is the source for power query in an Excel document. It takes some time to set up all of the transformations, and we would like to be able to reuse the steps when creating other documents which need to import into the data model files of the same format.

Is there a way to save the query and reuse it in another document? I've seen some references to copying the query text from the Advanced Editor, but it seems like there should be a better way of doing it.


Solution

  • Separation of data and PowerQuery transformations

    I assume, you opened your Excel data file and did all PowerQuery transformations within it. In order to separate them, you could either go for Peter's solution or you make two copies of that file, one for the data (e.g. "data.xlsx") and the other for the transformations (e.g. "PQ_transformations.xlsx"). Either way, you will have to do some adjustments.

    Adjustments

    Option 1: Select the data file within PowerQuery.

    Option 2: Apply transformations without editing PowerQuery

    The following setup assumes that you organize your data files in different folders. You can then copy your PQ file into each of these folders, open it and click on "Data"/"Update all" to apply your transformations to the data file in the given folder.

    Notes:

    let
        Source = Excel.CurrentWorkbook(){[Name="Table2"]}[Content],
        SetTypes = Table.TransformColumnTypes(Source ,{{"Current folder", type text}}),
        GetPathAsValue = SetTypes{0}[Current folder],
        ShowFilesInPath = Folder.Files(GetPathAsValue),
        FilterForDataFile = Table.SelectRows(ShowFilesInPath, each ([Name] = "Data.xlsx"))
    in
        FilterForDataFile