Ask Your Question
3

How to create an M function?

asked 2023-06-07 21:24:36 +0000

lakamha gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2023-06-07 21:38:01 +0000

huitzilopochtli gravatar image

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.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2023-06-07 21:24:36 +0000

Seen: 18 times

Last updated: Jun 07 '23