Ask Your Question

Revision history [back]

To create an M function, follow these steps:

  1. Open the Power Query Editor in Excel or Power BI.
  2. Click on the "New Source" button and select "Blank Query."
  3. In the formula bar, enter the name of your function followed by the parameters in parentheses. For example:

    MyFunction(parameter1 as text, parameter2 as number)
    
  4. Press "Enter" to create the function header.

  5. In the next line, begin the function code by typing "let" and pressing "Enter."
  6. Write the code to implement the function using M language.
  7. Close the function by typing "in" in a new line, followed by the expression that returns the output value.
  8. Press "Enter" to finish the function code.
  9. Click on "Close & Apply" to save the function and return to your report.

Your function is now created and can be called from other queries or expressions within your report. You can also save the function as a separate file with an extension ".pq" for future reuse.