Hello all,
I've written a transformation to look up a column header in a table and return the number of hours corresponding to that value. The original value in the cell is then divided by this number. The amount of header columns and their names can vary depending on the workbook so it doesn't make practical sense to repeat this transformation for every single column in the table. I'm wondering if there is a way this transformation can be applied to all columns starting with the first column to the right of Column1 ((index 1) and to the last column at the far right (index 12). I believe it would be best to refer to them by their index number rather than their name, if possible.
The top table is how the data originally looks, followed by the lookup table, and the resulting table after the transformation is applied to column 1/1/2022. Any help is greatly appreciated!
M-Code so far:
I've written a transformation to look up a column header in a table and return the number of hours corresponding to that value. The original value in the cell is then divided by this number. The amount of header columns and their names can vary depending on the workbook so it doesn't make practical sense to repeat this transformation for every single column in the table. I'm wondering if there is a way this transformation can be applied to all columns starting with the first column to the right of Column1 ((index 1) and to the last column at the far right (index 12). I believe it would be best to refer to them by their index number rather than their name, if possible.
The top table is how the data originally looks, followed by the lookup table, and the resulting table after the transformation is applied to column 1/1/2022. Any help is greatly appreciated!
M-Code so far:
Power Query:
let
Source = Excel.CurrentWorkbook(){[Name="Data"]}[Content],
#"Changed Type" = Table.TransformColumnTypes(Source,{{"Column1", type text}, {"1/1/2022", Int64.Type}, {"2/1/2022", Int64.Type}, {"3/1/2022", Int64.Type}, {"4/1/2022", Int64.Type}, {"5/1/2022", Int64.Type}, {"6/1/2022", Int64.Type}, {"7/1/2022", Int64.Type}, {"8/1/2022", Int64.Type}, {"9/1/2022", Int64.Type}, {"10/1/2022", Int64.Type}, {"11/1/2022", Int64.Type}, {"12/1/2022", Int64.Type}}),
#"Divided Column" = Table.TransformColumns(#"Changed Type", {{"1/1/2022", each _ / Hours[Hours]{List.PositionOf(Hours[Period],Date.FromText(Table.ColumnNames(#"Changed Type"){Table.Schema(#"Changed Type"){[Name="1/1/2022"]}[Position]}))}}})
in
#"Divided Column"