Forum Discussion

Mic1979's avatar
Mic1979
Post Partisan
1 year ago
Solved

Mutiply two columns using Lists and header name

Dear all   I have this table. Of course this is an abstract of my dataset:   I need to multiply the columns having "Volumes" and "Distribution" in the header, and I would like to use the li...
  • SundarRaj's avatar
    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