Language Translator | M (Power Query)

Code Translation of Doubling Function to M (Power Query)

This document outlines the translation of a function that doubles values in a list from a programming language to M code for Power Query, ensuring the logic remains intact and adheres to best practices.


Empty image or helper icon

Prompt

let
    doubleValues = (inputList) =>
        List.Transform(inputList, each _ * 2)
in
    doubleValues

Answer

Code Translation from Custom Function to M (Power Query)

Original Code Analysis

The provided code snippet is a standard function written in a programming language that doubles the values in a list. The main components are:

  • A function named doubleValues that accepts an inputList.
  • The function uses List.Transform to iterate over each element in inputList, multiplying each element by 2.

Translated M Code

Below is the equivalent code snippet in M (Power Query) that maintains the original logic and behavior:

let
    doubleValues = (inputList as list) as list =>
        List.Transform(inputList, each _ * 2)
in
    doubleValues

Explanation of M Code Structure

  • Function Definition: The doubleValues function is defined with parameters specifying that inputList is a list type and the function returns a list.
  • List Transformation: List.Transform processes each element of inputList, applying the multiplication in the each statement.

Conclusion

This M code translates the original function faithfully while adhering to Power Query's best practices. It is now ready for implementation in a Power Query environment.

Create your Thread using our flexible tools, share it with friends and colleagues.

Your current query will become the main foundation for the thread, which you can expand with other tools presented on our platform. We will help you choose tools so that your thread is structured and logically built.

Description

This document outlines the translation of a function that doubles values in a list from a programming language to M code for Power Query, ensuring the logic remains intact and adheres to best practices.