Search code examples
powerbipowerquerym

Powerquery categorise column by matching text values against a list


NextStep = Table.AddColumn(
    #"Clear nulls (approx 3)", 
    "Has process source", 
    each 
        [Source for process flows] <> "Source - No" and 
        [Source for process flows] <> "Source not found" and 
        Text.Lower([Source for process flows]) <> "source not available" and 
        [Source for process flows] <> null and 
        [Source for process flows] <> "?", 
    type logical
)

Is there a less dumb way to do this?

I want to convert a text column containing status updates into a True/False column.


Solution

  • You could name the column to something shorter:

    NextStep = Table.AddColumn(
        #"Clear nulls (approx 3)", 
        "Has process source", each
        let
            s = [Source for process flows],
            res = s <> "Source - No" and 
                  s <> "Source not found" and 
                  Text.Lower(s) <> "source not available" and 
                  s <> null and 
                  s <> "?"
        in
            res, type logical
    )
    

    and maybe use an exclusion list like @Peter suggested:

    excList = {"Source - No","Source not found",null,"?"},
    NextStep = Table.AddColumn(
        #"Clear nulls (approx 3)", 
        "Has process source", each
        let
            s = [Source for process flows],
            res = (not List.Contains(excList,s)) and
                  Text.Lower(s) <> "source not available"
        in
            res, type logical
    )