This time we’re going bigger than ever. Fabric, Power BI, SQL, AI and more. We're covering it all. You won't want to miss it.
Learn moreDid you hear? There's a new SQL AI Developer certification (DP-800). Start preparing now and be one of the first to get certified. Register now
I have a table (sample below) where the "Spend Year" columns can vary in number. I need to TRANSFORM these "Spend Year" columns by dividing them by the value in the "Count" column. This needs to be dynamic so that it the number of "Spend Year" columns does not matter.
I was able to find a way to ADD A COLUMN:
Table.AddColumn(#"Previous Step","New Column", each List.Sum(Record.ToList(Record.SelectFields(_,List.RemoveItems(Table.ColumnNames(#"Changed Type"), {"Account", "Billed Month", "Count"}))))/[Count])But I want the value returned by the division to stay in the respsective column for "Spend Year". Using Table.TransformColumns is resulting in an error, at least the way I've set it up.
Can anyone assist? @ImkeF the M Wizard?
I have a table as such:
Column Headers: Account | BilledMonth | Count | Spend Year 2 | Spend Year 1
| 123 | 1/1/2017 | 1 | 2205.95 | 0 |
| 123 | 2/1/2017 | 1 | 858.1776 | 0 |
| 123 | 3/1/2017 | 1 | 837.5276 | 0 |
| 123 | 4/1/2017 | 1 | 235.1256 | 0 |
| 123 | 5/1/2017 | 1 | 947.1374 | 0 |
| 123 | 6/1/2017 | 1 | 3698.3695 | 0 |
| 123 | 7/1/2017 | 1 | 3857.9387 | 0 |
| 123 | 8/1/2017 | 1 | 2439.8675 | 0 |
| 123 | 9/1/2017 | 1 | 3319.2321 | 0 |
| 123 | 10/1/2017 | 1 | 4480.2551 | 0 |
| 123 | 11/1/2017 | 1 | 3846.0694 | 0 |
| 123 | 12/1/2017 | 1 | -546.5412 | 0 |
| 123 | 1/1/2018 | 1 | -4885.7964 | 0 |
| 123 | 2/1/2018 | 1 | -5182.8906 | 0 |
| 789 | 6/1/2016 | 1 | 0 | 1054990.719 |
| 789 | 7/1/2016 | 1 | 0 | 1315482.823 |
| 789 | 8/1/2016 | 1 | 0 | 1323420.151 |
| 789 | 9/1/2016 | 1 | 0 | 1651866.191 |
| 789 | 10/1/2016 | 1 | 0 | 2181344.887 |
| 789 | 11/1/2016 | 1 | 0 | 2364539.433 |
| 789 | 12/1/2016 | 2 | 2226594.495 | 0 |
| 789 | 1/1/2017 | 2 | 1911725.76 | 0 |
| 789 | 2/1/2017 | 2 | 1319431.517 | 0 |
| 789 | 3/1/2017 | 2 | 1792099.668 | 0 |
| 789 | 4/1/2017 | 2 | 1705345.423 | 0 |
| 789 | 5/1/2017 | 2 | 2147638.828 | 0 |
| 789 | 6/1/2017 | 2 | -82614.0387 | 0 |
| 789 | 7/1/2017 | 2 | 58479.7707 | 0 |
| 789 | 8/1/2017 | 2 | 62815.7149 | 0 |
| 789 | 9/1/2017 | 2 | 82144.6631 | 0 |
| 789 | 10/1/2017 | 2 | 353836.2004 | 0 |
| 789 | 11/1/2017 | 2 | 679793.4773 | 0 |
| 789 | 12/1/2017 | 2 | 1147928.534 | 0 |
| 789 | 1/1/2018 | 2 | 1428323.833 | 0 |
| 789 | 2/1/2018 | 2 | 1374781.023 | 0 |
Solved! Go to Solution.
Solved:
Table.FromRecords(Table.TransformRows(#"Pivoted Column", (row) =>
let
Count = row[Count],
OtherColumns = List.RemoveItems(Record.FieldNames(row), {"Account", "Billed Month"}),
Transforms = List.Transform(OtherColumns, (name) => { name, (cell) => cell / Count})
in
Record.TransformFields(row, Transforms)))
Solved:
Table.FromRecords(Table.TransformRows(#"Pivoted Column", (row) =>
let
Count = row[Count],
OtherColumns = List.RemoveItems(Record.FieldNames(row), {"Account", "Billed Month"}),
Transforms = List.Transform(OtherColumns, (name) => { name, (cell) => cell / Count})
in
Record.TransformFields(row, Transforms)))
Check out the April 2026 Power BI update to learn about new features.
Sign up to receive a private message when registration opens and key events begin.
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
| User | Count |
|---|---|
| 34 | |
| 31 | |
| 30 | |
| 21 | |
| 16 |
| User | Count |
|---|---|
| 65 | |
| 53 | |
| 31 | |
| 23 | |
| 23 |