Forum Discussion

rm8168's avatar
rm8168
New Member
2 years ago
Solved

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...
  • ronrsnfld's avatar
    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.