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.
Prompt
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 ofinputList
. - The
each _ * 2
expression indicates that each element (represented by_
) should be doubled.
- The
This M code is now ready for use in Power Query while preserving the original logic from the provided code snippet.
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.