In Power BI Desktop, the M code for each query can be accessed from the Advanced Editor window within the Power Query Editor. With the Power Query Editor open, select a query of interest from the list of queries on the left and click on the Advanced Editor icon from the Home tab to access the following window:
As of the October 2017 release of Power BI Desktop, the Advanced Editor is limited to checking the syntax of the query. The colorization or highlighting of keywords, surrounding detection, and IntelliSense features available to DAX expressions is not yet available in Power BI Desktop. Given the importance of M queries to Power BI projects, as well as SQL Server Analysis Services 2017 and other Microsoft applications, external M editing tools, such as Visual Studio Code, are frequently used by dataset designers.
For the most common and simple data transformation tasks, such as filtering out rows based on one value of a column (for example, State = "Kansas"), the M code generated by the Power Query Editor usually requires minimal revision. For more complex queries with custom or less common requirements, the Power Query Editor graphical interface is less helpful and a greater level of direct M development is necessary.