Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The ultimate Microsoft Fabric, Power BI, Azure AI & SQL learning event! Join us in Las Vegas from March 26-28, 2024. Use code MSCUST for a $100 discount. Register Now

Reply
halifaxious
Frequent Visitor

multiply several columns by another column using M

I have a table that looks like this:

 

quantitySalaryEBPOH
1682025
7732127
0.5802530

 

I want to multiply each of the Salary, EBP and OH columns by Quantity, resulting in a table that looks like this:

quantitySalaryEBPOH
1682025
7511147189
0.54012.515

 

I know that I could beat it to death by adding 3 new columns and then removing the source columns.  e.g.

 

= Table.AddColumn(#"Source", "salaryCost", each [quantity] * [Salary], Currency.Type) 

= Table.AddColumn(#"addCol1", "ebpCost", each [quantity] * [EBP], Currency.Type) 

= Table.AddColumn(#"addCo2", "ohCost", each [quantity] * [OH], Currency.Type) 

= Table.RemoveColumns(#"addCol3",{"Salary","EBP","OH"}

 

But that is not very elegant.

 

I thought I might be able to do something like this:

 

= Table.TransformColumns( #"Source", {{"Salary", each Value.Multiply(_,[quantity])},{"EBP",each Value.Multiply(_,[quantity])},{"OH",each Value.Multiply(_,[quantity])}})

 

but I can't figure out how to get the value of [quantity] into Value.Multiply.  Is this even possible?

 

Is there a better way?

1 ACCEPTED SOLUTION
wdx223_Daniel
Super User
Super User

=Table.ReplaceValue(#"Source",each [quantity],"",(x,y,z)=>x*y,{"Salary","EBP","OH"})

View solution in original post

1 REPLY 1
wdx223_Daniel
Super User
Super User

=Table.ReplaceValue(#"Source",each [quantity],"",(x,y,z)=>x*y,{"Salary","EBP","OH"})

Helpful resources

Announcements
Fabric Community Conference

Microsoft Fabric Community Conference

Join us at our first-ever Microsoft Fabric Community Conference, March 26-28, 2024 in Las Vegas with 100+ sessions by community experts and Microsoft engineering.

February 2024 Update Carousel

Power BI Monthly Update - February 2024

Check out the February 2024 Power BI update to learn about new features.

Fabric Career Hub

Microsoft Fabric Career Hub

Explore career paths and learn resources in Fabric.

Fabric Partner Community

Microsoft Fabric Partner Community

Engage with the Fabric engineering team, hear of product updates, business opportunities, and resources in the Fabric Partner Community.

Top Solution Authors
Top Kudoed Authors