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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
mechanix85
Helper I
Helper I

Table.TransformColumns by criteria

Hello! How can I convert a column by a condition?

 

Something like this

if type = №2 and type2 = true then List.Product({_, -1}) else List.Product({_, 1})

???

 

 

Безымянный.png

 

1 ACCEPTED SOLUTION

Hi @mechanix85,

 

You could try this. It worked in my test.

 

#"Replaced Value" = 
          Table.ReplaceValue(#"Changed Type1",
          each [value],
          each if [type] = "No2" and [type2] = true then [value] * -1 else [value] * 1,
          Replacer.ReplaceValue,{"value"}),

Table.TransformColumns by criteria .jpg

 

 

 

 

 

 

 

 

 

 

 

 

Best Regards!

Dale

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

5 REPLIES 5
eziola
New Member

Dale! The Table.ReplaceValue solution works great! I was able to add a custom function to this solution so I can reference other columns like this:

 

=Table.ReplaceValue(

table,

each [ColumnToModify],

each fx_CustomFunction( [ColumnAsArgument1], [ColumnAsArgument2] ),

Replacer.ReplaceValue,

{"ColumnToModify"}

)

 

Question for the thread:

Does anyone know if there is a way to have Table.TransformColumns use other columns in the table as arguments to the transformation fuction? (like this...)


Table.TransformColumns(

table as table,

{{column_name, fx_CustomFunction ( [ColumnAsArgument1], [ColumnAsArgument2] ), DataType}}

)

 

Thanks for any insight on this!

 

 

Anonymous
Not applicable

Hi, 

 

  Dale's solution does work for me. However I was wondering if there is a way to transform multiple columns in one step? Right now I have to repeat on every column I wish to transform.

 

  Thanks.

 

Carl

v-jiascu-msft
Microsoft Employee
Microsoft Employee

Hi @mechanix85,

 

You could try this formula.

 

= if [type] = "No2" and [type2] = true then [value] * -1 else [value] * 1

Table.TransformColumns by criteria.jpg

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Notes: M is case sensitive.

 

Best Regards!

Dale

 

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

@v-jiascu-msft, Yes, i can do this, but I do not want to add new column... Table.TransformColumns can do it without new column, but I can not understand how to add a condition

Hi @mechanix85,

 

You could try this. It worked in my test.

 

#"Replaced Value" = 
          Table.ReplaceValue(#"Changed Type1",
          each [value],
          each if [type] = "No2" and [type2] = true then [value] * -1 else [value] * 1,
          Replacer.ReplaceValue,{"value"}),

Table.TransformColumns by criteria .jpg

 

 

 

 

 

 

 

 

 

 

 

 

Best Regards!

Dale

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Top Solution Authors