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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Mederic
Post Patron
Post Patron

Multiply column values depending values from another column

Hello everyone,

 

I'm trying to apply 2 methods to multiply a column by -1 depending on the value of another column,
The method with Table.ReplaceValue works very well but I can't manage to use it with Table.TransformColumns

How do I write this code correctly?

What is the best method for this transformation?

 

Thanks in advance

Best regards

ReplaceValue_TransformColumns.jpg

 

 

let
    Source = Excel.CurrentWorkbook(){[Name="Table1"]}[Content],
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Type", type text}, {"Amount", Int64.Type}}),
    #"Multiplied Column" = Table.TransformColumns(#"Changed Type", {{"Amount", each [Amoun], each if [Type] = "C" then [Amount] * 1 else [Amount], type number}})
in
    #"Multiplied Column"

 

 

TypeAmount

D792
D730
C342
D208
D862
D305
C463
C241
D217
C305
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Mederic ,

 

In the above case, it is not possible to use Table.TransformColumns() to get the other columns in the row. So you cannot use the value of the [Type] column as a condition.

 

Instead, you can use to create a new column (custom/conditional column) with the desired values and then remove the original [Amount] column.

 

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

View solution in original post

2 REPLIES 2
Mederic
Post Patron
Post Patron

Hello @Anonymous 

Thank you for your feedback,
I understand the difference between the 2 methods and that Table.ReplaceValue is the right one for this case.

Have a nice day

Best regards

Anonymous
Not applicable

Hi @Mederic ,

 

In the above case, it is not possible to use Table.TransformColumns() to get the other columns in the row. So you cannot use the value of the [Type] column as a condition.

 

Instead, you can use to create a new column (custom/conditional column) with the desired values and then remove the original [Amount] column.

 

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.