Forum Discussion
Is there a Power Query or DAX Equivalent for this code in Excel?
- 5 years ago
Hi Anonymous
Yes you can first define the list:
RefList_ = {"Apple", "Banana", "Orange", "Grape"},
then you can add a custome column with the code
= if List.Contains(RefList_, [ColumnA2]) then [ColumnA2] else null
Please mark the question solved when done and consider giving a thumbs up if posts are helpful.
Contact me privately for support with any larger-scale BI needs, tutoring, etc.
Cheers
- 5 years ago
Hi Anonymous
This M code will search for each word in the ItemList and return all matching words from the Items column, in a new column.
Here's a sample PBIX file with the code
let ItemList = {"Apple", "Banana", "Orange", "Grape"}, Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45Wck4sKsovUXAqSk1MUfAvSsxLT1VwTU8vVoqNBQA=", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [Items = _t]), #"Changed Type" = Table.TransformColumnTypes(Source,{{"Items", type text}}), #"Added Custom" = Table.AddColumn(#"Changed Type", "Matches", each List.Accumulate ( ItemList, "", (state, current) => if List.Contains(Text.Split([Items], " "), current) then state & " " & current else state )) in #"Added Custom"String matching is case sensitive. If you want it to be case insensitive then add Comparer.OrdinalIgnoreCase to List.Contains :
List.Contains(Text.Split([Items], " "), current, Comparer.OrdinalIgnoreCase)Phil
If I answered your question please mark my post as the solution.
If my answer helped solve your problem, give it a kudos by clicking on the Thumbs Up.
Power Query = List.Skip({"Apple", "Banana", "Orange", "Grape"},each not Text.Contains(A2text,_)){0}?
DAX =MAXX(FILTER({"Apple", "Banana", "Orange", "Grape"},SEARCH([Value],A2text,,0)),[Value])