Forum Discussion

aliciab425's avatar
aliciab425
Regular Visitor
4 years ago
Solved

Custom Column for Multiple IF & And Statements

The below formula is cauclated in Excel. I would like to see if this would be easily calculated in Power BI, however, I currently have AST1, AST2, and AST3, I need to add AST4, AST5, and AST6. Is thi...
  • AlexisOlson's avatar
    4 years ago

    If I understand your logic correctly, this should work:

    let
        Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("i45WcvJx9PM2VNKBMIxgDGOlWJ1opRCQBIyAC+BUCZfAqjrECMlMNO1wV+CXgJqL6WYMs0OwageqigUA", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [AST1 = _t, AST2 = _t, AST3 = _t]),
        #"Added Custom" = Table.AddColumn(Source, "Custom", each
            let
                L = List.Distinct(List.Select({[AST1],[AST2],[AST3]}, each not Text.StartsWith(_, "BLANK")))
            in
                if List.Count(L) = 0 then "Investigate"
                else if List.Count(L) > 1 then "House"
                else L{0},
            type text)
    in
        #"Added Custom"

    This takes the list of values in AST1, AST2, AST3 and removes the items starting with "BLANK". Then it removes any duplicates and returns different values depending on how many items remain.