Forum Discussion

tt211595's avatar
tt211595
Frequent Visitor
3 years ago
Solved

Rowwise minimum without exact column name

Hello! Say I have a table with three columns (ID, Column2, and Column3). I'd like to add a new column named Column4 that has a row-wise minimum calculated using Column2 and Column3. Normally, in Powe...
  • Ashish_Mathur's avatar
    3 years ago

    Hi,

    This M code works

    let
        Source = Excel.CurrentWorkbook(){[Name="Data"]}[Content],
        #"Changed Type" = Table.TransformColumnTypes(Source,{{"ID", type text}, {"Column2", Int64.Type}, {"Column3", Int64.Type}}),
        selectedheaders = List.Select(Table.ColumnNames(#"Changed Type"),each Text.Contains(_ ,"Column")),
        Custom1 = #"Changed Type",
        #"Added Custom" = Table.AddColumn(Custom1, "Min value", each List.Min(Record.ToList(Record.SelectFields(_,selectedheaders))), type number)
    in
        #"Added Custom"

    Hope this helps.