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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
grsmith
Frequent Visitor

Transform Columns using Dynamic List

Hi there; I've been banging my head against this for a while:

 

I am trying to multiply all value columns in my table by -1.  The number of value columns can vary - and I generate a list of column names (NewFieldNames).

 

I am trying to use the Table.TransformColumns method as below:

 

= Table.TransformColumns(Source, each {NewFieldNames,  each _* -1 , type number})

 

I get the error:

  Expression.Error: We cannot convert a value of type Function to type List.
  Details:
  Value=Function
  Type=Type

 

Any ideas on getting this to work?

1 ACCEPTED SOLUTION

Hi grsmith,

 

Based on your description, you want to multiply all value in your table with -1, right?

You can use R Script below instead:

# 'dataset' holds the input data for this script

len_row <- nrow(dataset)

len_column <- ncol(dataset)

for (i in 1:len_row)

{

    for (j in 1:len_column)

    {

         dataset[i, j] = dataset[i, j] * -1

    }

}

result <- dataset

 

And please refer to Run R scripts in Power BI Desktop.

 

Regards,

Jimmy Tao

View solution in original post

3 REPLIES 3
Greg_Deckler
Community Champion
Community Champion

Maybe:

 

= Table.TransformColumns(Source, each {NewFieldNames(),  each _* -1 , type number})

Assuming that function returns a list.



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Thanks for the message Greg; unfortunately this doesn't solve the issue - I get the same error as previous.

 

A bit more experimenting overnight and the below works for the first column (i.e. the first item in the list NewFieldNames):

 

= Table.TransformColumns(#"Multiplied Column1", {NewFieldNames{0} , each _ * -1, type number})

 

I understand that the TransformColumns method requires the second parameter to be all functions, so I'm not sure why the above works as it only returns the first string for the first column - i.e. not a function.

 

I need this to iterate through each list item (i.e. all field names), and apply the transformation (* -1) to each line in the data for that field.  I just don't know how that syntax is written.

 

 

 

Hi grsmith,

 

Based on your description, you want to multiply all value in your table with -1, right?

You can use R Script below instead:

# 'dataset' holds the input data for this script

len_row <- nrow(dataset)

len_column <- ncol(dataset)

for (i in 1:len_row)

{

    for (j in 1:len_column)

    {

         dataset[i, j] = dataset[i, j] * -1

    }

}

result <- dataset

 

And please refer to Run R scripts in Power BI Desktop.

 

Regards,

Jimmy Tao

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

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.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.