Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
cmengel
Advocate II
Advocate II

Power Query M Code Management Best Practice?

Power Query M Code Management Best Practice?

 

The first time I clicked on the Advanced Editor in Power Query my eyes glazed over.  What in the world am I even looking at?  Once it I realized each line of code corresponded to one step in Power Query Applied Steps things got a lot better - fast.

 

As I spent more time working on M code a few things stood out to me:

  • Working with M Code in the Advanced Editor was a chore -> lots of scrolling
  • The code is unformatted ->  harder to read, learn and modify
  • The code only existed in the PBIX file -> no backup, hard to share with colleagues,  and if I wanted to look into something I had to open the PBIX file

 

Enter Visual Studio Code (VSC).  VSC is a free open source code editing tool that has embedded Git, supports debugging, syntax highlighting and intelligent code completion.  VSC has a module for Power Query/M Code!

 

With VSC, I can easily:

  • Write native M Code with the aid of intellisense
  • Format the code to make it easier to write, read and troubleshoot (and learn!)
  • Backup the code to a repository organized into folders
  • Share my Power Query M Code with my colleagues via the repository
  • Easily review the M Code for all my reports and dataflows in one place
  • Leverage M Code 'patterns' to build data models consistently across all my reports
  • Ensure my Power Queries are structured the same way for greater consistency

 

In short, I use VSC to be more consistent and efficient in my Power Query development.  This helps reduce the time to prepare and import data into Power BI and build the data model.  All with the peace of mind of having my hard work backed up safely.  To me, this feels like a best practice.

 

I highly recommend taking a look at VSC to help you manage your Power Query M Code!

1 REPLY 1
lbendlin
Super User
Super User

Good points, especially the version control/collaboration part. 

 

Doesn't really seem to help with formatting (use powerqueryformatter.com ) or with documenting your code  (for that you need to be disciplined and add the boilerplate meta code manually).

 

What I don't userstand is the connection to Power BI Desktop, or the lack thereof.  Correct me if I am wrong but I don't think VSC can open .pbix files or work with the XMLA endpoint?

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.