Forum Discussion

BR-MSBI's avatar
BR-MSBI
Frequent Visitor
2 years ago
Solved

If, Or, Else not working

I am working with customer data and I am trying to segment them based on various demographic and lifestage information e.g. if someone is 18-21 years old or 35-39 years old and working full time or p...
  • lbendlin's avatar
    lbendlin
    2 years ago

    use PowerQueryFormatter.com to bring your code into a readable format

    let
      a = 
        if List.Contains({"Under 18", "18-21", "22-29", "30-34", "35-39"}, [Q1_Age])
          and (
            {
              [#"Q6_Employment_Working full time (30 hours or more work per week)"]
                = 1 or [#"Q6_Employment_Working part time (under 30 hours work per week)"]
                = 1
            }
          )
          and ([Q2_Parent_None of these apply] = 1)
          and List.Contains(
            {"Single/Never married", "De facto/Living with partner but not married"}, 
            [Q3_Marital_Status]
          )
        then
          "SEGMENT A"
        else
          null
    in
      a

     

    Then validate if that is the actual logic you wanted to implement