Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago
Solved

multiply columns by one column

Hi All

 

I need to transform a bunch of columns by multiplying them on row level by values in a column:

Ex in tabel below I need to multiply Column2, Column3 & Column4 by Column1

Column1Column2Column3Column4
2121
3113

 

After transformation of columns we get:

Column1Column2Column3Column4
2242
3339

 

It feels like one should be able to do this in one step with M code. what I basicly whant to do is:  for each of these columns multiply the value on each row with the value in this column on same row.

Does anyone know if this is possible?


  • Anonymous's avatar
    Anonymous
    3 years ago

    Sorted it out my self, this worked.

    Table.FromRecords(Table.TransformRows(#"Changed Type", (x) => Record.TransformFields(x, List.Transform({"Column2", "Column3", "Column4"}, (y) => {y, each x[Column1] * _}))))

1 Reply

  • Anonymous's avatar
    Anonymous
    Not applicable

    Sorted it out my self, this worked.

    Table.FromRecords(Table.TransformRows(#"Changed Type", (x) => Record.TransformFields(x, List.Transform({"Column2", "Column3", "Column4"}, (y) => {y, each x[Column1] * _}))))