How to write Logical in HH roster Logical

Hi Survey Solution User !!!
I have some question want all you here help me to solve them.
For hhs roster, if spouse have sex 1= male 2 = female. I want if the respondent is head of hh contain sex=1 and spouse cannot same sex, it must to sex= 2. my question is how to write the logic?

You must be familiar with LINQ.
Here is one solution :
let the variable rel be the relationship of the member with the head: (so 1 is the head of the household and 2 is the spouse), hhold is the roster.

//if it is the household head
rel== 1 ?

//…must not have a spouse having the same sex

hhold.Count (x=>x.rel ==2 && x.sex ==sex) ==0 :

// if it is the spouse

rel== 2 ?

//…must not have the same sex with the head

hhold.Count (x=>x.rel==1 && x.sex==sex) ==0:

true

See this article for a short introduction to LINQ, a few worked examples, and links to further (non-SuSo) resources.

Additionally, you can find some good content in this public questionnaire, which includes a lot of the content and typical validations of the household roster–including the one you’re requesting, as validation #2 for relat.

1 Like

Thanks you!!! for sharing this question I followed ur comment it working well