Forum Discussion
Mutiply two columns using Lists and header name
- 1 year ago
Hi Mic1979 ,
This error is because you are multiplying Records with Records when you say Record.Field (_,SelectVolumeColumn) * Record.Field (_,SelectDistributionColumn).You need to convert Record into a value in order to multiply them together. See the images below. I'll leave the code below. Thanks
Solution:
Code:
let
Source =
#table(
{"Region (DB Key)", "Project_Step (DB Key)", "Function_Description (DB Key)", "Volumes Year3", "Product_Series_Description (EXPAND)", "Distribution (EXPAND)"},
{
{"AM.", "Step 2.2", "ON/OFF", 715.4, "2 way", 1},
{"AM.", "Step 2.2", "Prop.", 306.6, "2 way", 1},
{"APAC", "Step 2.2", "ON/OFF", 444.5, "2 way", 1},
{"EMEA", "Step 2.2", "ON/OFF", 136.6666667, "2 way", 1},
{"APAC", "Step 2.2", "Prop.", 190.5, "2 way", 1},
{"EMEA", "Step 2.2", "Prop.", 273.3333333, "2 way", 1}
}
),
Change_Volume_Header = Table.TransformColumnNames (Source, each if Text.Contains (_,"Volumes") then _& " OLD" else _),
SelectVolumeColumn = List.Select (Table.ColumnNames (Change_Volume_Header), each Text.Contains (_, "Volumes")),
SelectDistributionColumn = List.Select (Table.ColumnNames (Change_Volume_Header), each Text.Contains (_, "Distribution")),
Custom1 = SelectDistributionColumn,
Custom2 = Table.AddColumn ( Change_Volume_Header , "Volumes_Year3New" , each Record.ToList ( Record.SelectFields ( _ , SelectVolumeColumn ) ){0} * Record.ToList ( Record.SelectFields ( _ , SelectDistributionColumn ) ){0} )
in
Custom2
Hi Mic1979 ,
This error is because you are multiplying Records with Records when you say Record.Field (_,SelectVolumeColumn) * Record.Field (_,SelectDistributionColumn).
You need to convert Record into a value in order to multiply them together. See the images below. I'll leave the code below. Thanks
Solution:
Code:
let
Source =
#table(
{"Region (DB Key)", "Project_Step (DB Key)", "Function_Description (DB Key)", "Volumes Year3", "Product_Series_Description (EXPAND)", "Distribution (EXPAND)"},
{
{"AM.", "Step 2.2", "ON/OFF", 715.4, "2 way", 1},
{"AM.", "Step 2.2", "Prop.", 306.6, "2 way", 1},
{"APAC", "Step 2.2", "ON/OFF", 444.5, "2 way", 1},
{"EMEA", "Step 2.2", "ON/OFF", 136.6666667, "2 way", 1},
{"APAC", "Step 2.2", "Prop.", 190.5, "2 way", 1},
{"EMEA", "Step 2.2", "Prop.", 273.3333333, "2 way", 1}
}
),
Change_Volume_Header = Table.TransformColumnNames (Source, each if Text.Contains (_,"Volumes") then _& " OLD" else _),
SelectVolumeColumn = List.Select (Table.ColumnNames (Change_Volume_Header), each Text.Contains (_, "Volumes")),
SelectDistributionColumn = List.Select (Table.ColumnNames (Change_Volume_Header), each Text.Contains (_, "Distribution")),
Custom1 = SelectDistributionColumn,
Custom2 = Table.AddColumn ( Change_Volume_Header , "Volumes_Year3New" , each Record.ToList ( Record.SelectFields ( _ , SelectVolumeColumn ) ){0} * Record.ToList ( Record.SelectFields ( _ , SelectDistributionColumn ) ){0} )
in
Custom2
Working..thanks