Forum Discussion
CarlosFF
5 years agoFrequent Visitor
List.Select using a list from column names. Count ocurrences in columns starting with string.
Hi Im trying to count Yes/No/NA occurrences in the columns that starts with a scpecific string. Doing in this way will permit use the same code in tables with different number of columns. If ...
- 5 years ago
Hi.
I have found this approach in
MyCols = List.Buffer(List.Select(Table.ColumnNames(#"Reordered Columns"), each Text.StartsWith(_, "GROUP_"))), GROUP_1_Yes = Table.AddColumn(#"Reordered Columns" , "GROUP_1_Yes", each List.Count(List.Select(Record.ToList(Record.SelectFields(_,MyCols)), each _ = "Yes")) ,Int64.Type),Thank you all for your help!
🙂
CNENFRNL
Community Champion
5 years agoHi, CarlosFF , it's simple enough like this,
GROUP1.CountYes = Table.AddColumn(#"Reordered Columns", "GROUP1.CountYes", each List.Count(List.Select(Record.ToList(_),each _ = "Yes")),Int64.Type),
GROUP1.CountNo = Table.AddColumn(GROUP1.CountYes, "GROUP1.CountNo", each List.Count(List.Select(Record.ToList(_),each _ = "No")), Int64.Type),CarlosFF
5 years agoFrequent Visitor
Hi. It looks simple.
Where you put the list name?
GROUP1.CountNo = Table.AddColumn(GROUP1.CountYes, "GROUP1.CountNo", each List.Count(List.Select(Record.ToList(MYLIST),each _ = "No")), Int64.Type),
As argument of Record.ToList it gives the following error, using MyList1 or MyList2 (items with brackets)
Expression.Error: We cannot convert a value of type List to type Record.
Details:
Value=[List]
Type=[Type]
Thanks!