Searching for multiple values - the basics

TcO_CDX

New member
Joined
Oct 17, 2016
Messages
5
Reaction score
0
Points
0
I have read the other thread posted in this forum regarding searching for multiple values, but I don't think it quite fits my needs - but I may not fully understand what it is doing.
I have column "Mfg_Lot_Details" that is of various length for each record. Somewhere within the text string is "LTT", "LTM", or "LDP". I want to create a custom column that extract the one of those values or if none of those is there, then "Unknown".
In plain English, it would look something like this:

"MFG_Catg" =
If "Mfg_Lot_Details" contains "LTT", then "LTT",
If "Mfg_Lot_Details" contains "LTM", then "LTM",
If "Mfg_Lot_Details" contains "LDP", then "LDP",
Else "Unknown"

The "Mfg_Lot_Details" is only going to contain one of the three values (not multiple) and I put the "Unknown" in there just in case it doesn't have one of the three (haven't seen it happen yet).

I am new to Power Query and am learning M (even read Ken & Miguel's book). But after searching for several hours and reading several posts, I am not finding any good examples. Or perhaps I am not searching for the correct key words.

I've read about SWITCH as well, but I'm not sure if I should use it.

Any assistance in helping to explain the basics for searching for multiple criteria would be greatly appreciated; or pointing me to relevant posts.

Thank you,
TcO
 
Hey TcO_CDX,

hope this helps ;)

NewColumn = Table.AddColumn(#"Your previous step", "MFG_Catg", each if Text.Contains([Mfg_Lot_Details], "LTT") then "it has LTT" else if Text.Contains([Mfg_Lot_Details], "LTM") then "it has LTM" else if Text.Contains([Mfg_Lot_Details], "LDP") then "it has LDP" else "Unknown" )
 
Last edited:
Alternatively:

Code:
NewColumn = Table.AddColumn(Source, "MFG_Catg", (This) => List.Select({"LTT","LTM","LDP","Unknown"},each Text.Contains(This[MFG_Lot_Details]&"Unknown",_)){0})
 
Thank you both for the quick response. About 10 minutes after I posted, I found a blog article from MyOnlineTrainingHub about Power Query If Statements and it showed the Conditional If feature in PQ (which I had never seen before).
I used it to get the same results that Kaso provide - thanks Kaso for taking the time to respond. It is nice to validate that I was on the right track.
Marcel - thanks for the alternate code. This (no pun intended) helps me understand the other post regarding this topic much more.
I will definitely need to do more reading on "This" topic.

TcO
 
Back
Top