Language Translator | M (Power Query)

Doubling Values Function in Power Query

This document explains the `doubleValues` function that doubles each element in a list using M (Power Query) code, providing a direct translation from an earlier code snippet. It highlights the function's structure and transformation logic.


Empty image or helper icon

Prompt

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

Answer

Code Analysis

The provided code snippet defines a function doubleValues that takes a list (inputList) as an argument and returns a new list where each element is multiplied by 2. The key components are:

  • Function Definition: A lambda function that transforms each element using List.Transform.
  • Transformation Logic: Each element of the input list is multiplied by 2.

Translation to M (Power Query)

The equivalent M (Power Query) code that maintains the same logic and functionality is structured as follows:

M Code Snippet

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

Explanation of M Code

  • Function Signature:
    • (inputList as list) as list: Specifies the input type as a list and the output type as a list.
  • List.Transform:
    • The List.Transform function applies the transformation logic to each element of inputList.
    • The each _ * 2 expression indicates that each element (represented by _) should be doubled.

This M code is now ready for use in Power Query while preserving the original logic from the provided code snippet.

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 explains the doubleValues function that doubles each element in a list using M (Power Query) code, providing a direct translation from an earlier code snippet. It highlights the function's structure and transformation logic.