Home > database >  Is there a way to link a single M Code document to multiple workbooks?
Is there a way to link a single M Code document to multiple workbooks?

Time:02-11

I have several workbooks linked to the same set of CSV files. I use the same Power Query transform steps for each CSV file in each workbook. Instead of copying M code from the advanced editor of one workbook and pasting it into the advanced editor of another, is there somewhere I can store a "master" M code document? I would like to be able to link all workbooks to a single text file containing M code so that when I make changes in this master document the Power Query transformations are made in each linked workbook - similar to style sheets in css.

CodePudding user response:

See https://blog.crossjoin.co.uk/2014/02/04/loading-power-query-m-code-from-text-files/

let
//Load M code from text file
// https://blog.crossjoin.co.uk/2014/02/04/loading-power-query-m-code-from-text-files/
Source = Text.FromBinary(File.Contents("C:\directory\MyMCode.txt")),
//Evaluate the code from the file as an M expression
EvaluatedExpression = Expression.Evaluate(Source, #shared)    
in
EvaluatedExpression 

CodePudding user response:

Another approach to this is to use Dataflows. These are essentially queries stored in the Power BI Service that you can connect your Power BI files to.

Recommended reading:

https://docs.microsoft.com/en-us/power-bi/transform-model/dataflows/dataflows-introduction-self-service

https://radacad.com/what-are-the-use-cases-of-dataflow-for-you-in-power-bi

  • Related