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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Jsaidtecnimont
Frequent Visitor

How to change units of multiple columns in one table?

Hello everybody,


I have a table that has specific columns that are specifically in the imperial units of measure and I want to change all the quantities in my table to become imperial. I've accomplished it but I think it's very inefficient as you can see below, is there a way where I can do this all in one step? I want to also do this in power query so that I can automate the processing of the same looking tables in the future too.

 

#"QTY IFC to metric" = Table.ReplaceValue(#"QTY IFR to metric", each [QTY IFC], each if[UM QTY] = "CubicYard" then [QTY IFC] * 0.76455486 else if [UM QTY] = "Foot" then [QTY IFC] * 0.3048 else if [UM QTY] = "Pound" then [QTY IFC] * 0.45359237 else [QTY IFC], Replacer.ReplaceValue, {"QTY IFC"}),
#"QTY VD to metric" = Table.ReplaceValue(#"QTY IFC to metric",each [QTY VD], each if[UM QTY] = "CubicYard" then [QTY VD] * 0.76455486 else if [UM QTY] = "Foot" then [QTY VD] * 0.3048 else if [UM QTY] = "Pound" then [QTY VD] * 0.45359237 else [QTY VD], Replacer.ReplaceValue, {"QTY VD"}),
#"QTY ACC to metric" = Table.ReplaceValue(#"QTY VD to metric",each [QTY ACC], each if[UM QTY] = "CubicYard" then [QTY ACC] * 0.76455486 else if [UM QTY] = "Foot" then [QTY ACC] * 0.3048 else if [UM QTY] = "Pound" then [QTY ACC] * 0.45359237 else [QTY ACC], Replacer.ReplaceValue, {"QTY ACC"})

 

thank you in advance! 

1 ACCEPTED SOLUTION
v-jingzhang
Community Support
Community Support

Hi @Jsaidtecnimont 

 

This is possible. Please try this

ReplaceMultipleColumns = Table.ReplaceValue(#"previous step name", each List.Contains({"CubicYard", "Foot", "Pound"}, [UM QTY]), each if [UM QTY] = "CubicYard" then 0.76455486 else if [UM QTY] = "Foot" then 0.3048 else if [UM QTY] = "Pound" then 0.45359237 else 1, (x,y,z)=> if y then z * x else x, {"QTY IFC", "QTY VD", "QTY ACC"})

vjingzhang_0-1682306258185.png

I get the idea from an old thread Replacing values in multiple columns based on condition in Power Query and an article Replace Values in Power Query M (Ultimate Guide) - BI Gorilla. Hope they will be helpful!

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.

 

View solution in original post

1 REPLY 1
v-jingzhang
Community Support
Community Support

Hi @Jsaidtecnimont 

 

This is possible. Please try this

ReplaceMultipleColumns = Table.ReplaceValue(#"previous step name", each List.Contains({"CubicYard", "Foot", "Pound"}, [UM QTY]), each if [UM QTY] = "CubicYard" then 0.76455486 else if [UM QTY] = "Foot" then 0.3048 else if [UM QTY] = "Pound" then 0.45359237 else 1, (x,y,z)=> if y then z * x else x, {"QTY IFC", "QTY VD", "QTY ACC"})

vjingzhang_0-1682306258185.png

I get the idea from an old thread Replacing values in multiple columns based on condition in Power Query and an article Replace Values in Power Query M (Ultimate Guide) - BI Gorilla. Hope they will be helpful!

 

Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.

 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.