Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
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 Power Query, I'd do something like this:
new_column = Table.AddColumn(Source, "Column4", each List.Min({[Column2], [Column3]}), Int64.Type)
Is there a way I can do the same thing without using the exact column names? For example, instead of listing [Column2] and [Column3] in List.Min(), what if I wanted to calculate row-wise minima across all columns containing "Column" in the header with something like Text.Contains()?
Thanks in advance!
Solved! Go to Solution.
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.
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.
This is perfect. Thanks!
You are welcome.
Pls try this
List.Min({
Record.FieldValues(_){1},
Record.FieldValues(_){2}}
)
Thank you, this is helpful!
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
109 | |
106 | |
87 | |
75 | |
66 |
User | Count |
---|---|
125 | |
114 | |
98 | |
81 | |
73 |