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 again,
I think that approach is mostly working but instead of showing the text "segment A" it is showing "error" is it do with the value being a numeric? Below is the syntax
if List.Contains({"Under 18","18-21","22-29","30-34","35-39"},[Q1_Age]) and List.Contains({1},[#"Q6_Employment_Working full time (30 hours or more work per week)"]) and List.Contains({1},[#"Q6_Employment_Working part time (under 30 hours work per week)"]) and List.Contains({1},[Q2_Parent_None of these apply]) and List.Contains({"Single/Never married", "De facto/Living with partner but not married"}, [Q3_Marital_Status]) then "SEGMENT A" else 0
=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
or [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
- BR-MSBI2 years agoFrequent Visitor
Firstly, I do appreciate you helping me through this. Using the syntax above it is only producing 0 for all rows. Why do think that is happening?
- lbendlin2 years ago
Super User
Power Query is case sensitive. Most likely you have spelling differences.
Please provide sample data that covers your issue or question completely, in a usable format (not as a screenshot).
Do not include sensitive information or anything not related to the issue or question.
If you are unsure how to upload data please refer to https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-Forum/ba-p/963216
Please show the expected outcome based on the sample data you provided.
Want faster answers? https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447523- BR-MSBI2 years agoFrequent Visitor
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!