Forum Discussion
rm8168
2 years agoNew Member
PQ M-code not recognizing empty cell in email field
Hi Community, I'm a newbie to forum so I hope I'm posting correctly. I searched forum and even tried ChatGPT for a solution. Here is the scenario. I have large Excel table containing fields of "ema...
- 2 years ago
Because of the way null behaves in performing logical operations, one solution is to re-arrange your statement so that you are checking for the null first.
#"Added Custom" = Table.AddColumn(#"Changed Type", "SalesChannel", each if (Text.Trim([email]) = "" or [email] = null) and [StoreName] = "Corporate" then "In-Store" else if Text.Contains([email], "amazon") then "Amazon" else if Text.Contains([email], "ebay") then "eBay" else if [StoreName] = "Event Store Server" then "Event Store" else if (Text.Trim([email]) = "" or [email] = null) and [StoreName] = "Corporate" then "In-Store" else "Co Web" )The problem is that a statement like:
Text.Contains([email], "amazon")will return null and not a logical if [email] contains null. By checking for null first in your if statement, you bypass that problem.
ChielFaber
2 years agoSuper User
Try-out adding an extra step in the if clause
Else if Text.Length([email]) = 0 then null
When there are additional spaces you might need to add Text.Trim like
Text.Length(Text.Trim([email])) = 0 then null
You can replace the null with any desired output. Like "no-email"
Hope this helps