Value.Multiply

D

T

The M Code Behind the Power Query M function Value.Multiply

Understanding the Value.Multiply Function

The Value.Multiply function is a simple but powerful function that allows users to multiply two values together. It takes two arguments: Value1 and Value2. The function then multiplies these two values together and returns the result. The syntax for the function is as follows:


Value.Multiply(Value1, Value2)


Using the Value.Multiply Function in Power Query

The Value.Multiply function can be used in a variety of ways to manipulate data in Power Query. Here are some examples:

Example 1: Multiplying Two Columns Together

Suppose we have a table with two columns, Price and Quantity, and we want to create a new column that calculates the total cost of each item. We can use the Value.Multiply function to do this. Here’s the M code:


= Table.AddColumn(#"PreviousStep", "TotalCost", each Value.Multiply([Price], [Quantity]))


This code adds a new column called “TotalCost” to the table and calculates the total cost by multiplying the Price and Quantity columns together.

Example 2: Multiplying a Column by a Fixed Value

Suppose we have a table with a column called “Weight” and we want to convert the values in this column from pounds to kilograms. We know that 1 pound is equal to 0.453592 kilograms. We can use the Value.Multiply function to do this. Here’s the M code:


= Table.TransformColumns(#"PreviousStep",{{"Weight", each Value.Multiply(_, 0.453592)}})


This code transforms the “Weight” column by multiplying each value by 0.453592 to convert it to kilograms.

Example 3: Multiplying Several Columns Together

Suppose we have a table with three columns, Length, Width, and Height, and we want to calculate the volume of each item. We can use the Value.Multiply function to do this. Here’s the M code:


= Table.AddColumn(#"PreviousStep", "Volume", each Value.Multiply(Value.Multiply([Length], [Width]), [Height]))


This code adds a new column called “Volume” to the table and calculates the volume by multiplying the Length, Width, and Height columns together.

The Value.Multiply function is a powerful tool that allows users to multiply two values together in Power Query. It can be used in a variety of ways to manipulate data, including multiplying columns together, multiplying a column by a fixed value, and multiplying several columns together to calculate a new value. By understanding the M code behind this function, users can unlock the full potential of Power Query and take their data manipulation skills to the next level.

Power Query and M Training Courses by G Com Solutions (0800 998 9248)

Upcoming Courses

Contact Us

    Subject

    Your Name (required)

    Company/Organisation

    Email (required)

    Telephone

    Training Course(s)

    Your Message

    Upload Example Document(s) (Zip multiple files)