Forum Discussion
Dicken
Post Prodigy
1 year agoPower Query conditional column selection
Hi , I wanted to select columns that contained a certain value and came up with this , but has anyone any ideas for a different approach ? here just selectign columns that contian "X". BTW, should...
- 1 year ago
Your table = Source.
You can use this anywhere you would normall use SelectColumns (or RemoveColumns)
= Table.SelectColumns(Source,List.Select(Table.ColumnNames(Source), each Text.Contains(_, "X", Comparer.OrdinalIgnoreCase)))I made the match case INsenistive, remove the Comparare.OrdinalIgnoreCase if you don't want that.
Omid_Motamedise
Super User
1 year agoHi Dicken
Table.UnpivotOtherColumn is really useful for this question, so use the below code
let
Source = #table(
type table [A = text, B = text, C = text, D = text],
{{"a,b", "X,c", "c,c", "a,d"}, {"c,c", "a,a", "a,X", "d,c"}}
),
Custom1 = Table.UnpivotOtherColumns(Source,{},"Columns","Value"),
#"Filtered Rows" = Table.SelectRows(Custom1, each Text.Contains([Value], "X"))
in
#"Filtered Rows"