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, let me try to compare the two to see if there any spelling or case differences first. I am comfortable sharing the data in an open forum like this.
Will circle back!
So the Syntax is certainly working, I know that because I have only written the syntax for one segment and the rows that are showing as errors are where it needs to display "segment A", which is great!! so when I look at the errors this is what I see "Expression.Error: We cannot convert a value of type List to type Logical.
Details:
Value=[List]
Type=[Type]
Doesn't this mean tha one of the lists can't be calculated becuase it is text?
- lbendlin2 years ago
Super User
Please show your code.
- BR-MSBI2 years agoFrequent Visitor
=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
- lbendlin2 years ago
Super User
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