Forum Discussion
If, Or, Else not working
- 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 aThen validate if that is the actual logic you wanted to implement
Hi there,
Thank you for your response, forgive my naivete! you are right, it is power query to add a new conditional column. I used your suggestion to protect the ORs with parentheses and while there were no syntax errors, everything is converted to 0.
I have 3 segments, so if someone is between the ages of 40 to 64 yrs 'AND' they thier marital status is Defacto, divorced, engaged, married, seperated or widowed 'AND' working full time, part time or semi retired 'then' they fit into "Segment C" else ...(next set of rules for next segment)
Does that make sense?
= if List.Contains({40..64},[age])
and List.Contains({"Defacto","divorced","engaged","married","seperated","widowed"},[marital status])
and List.Contains({"full time","part time","semi retired"},[working])
then "Segment C"
else ...