Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateJoin 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.
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 July 2025 Power BI update to learn about new features.
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
User | Count |
---|---|
63 | |
59 | |
56 | |
38 | |
29 |
User | Count |
---|---|
82 | |
62 | |
45 | |
41 | |
40 |