# Count using several conditions based on Roster

Good evening,
I use Long Integer variable expression to count women in a roster that fulfil several conditions based on several subsequent answers in the roster.
Following the questions about all pregnancies (list_pregn), I have a roster (ros_preg) that records answers on pregnancies. I want to count the number of women who gave birth after the year 2011 (var p220Aby>2011) and only if pregnancy lasted longer than 5 months (var p220AC>5)

The following syntax give errors:
ros_preg.Count((x=>x.p220ABy>2011) && (x=>x.p220AC>=5))
ros_preg.Count(x=>x.p220ABy>2011 && x=>x.p220AC>=5)

If I use those conditions separately, one by one, there is no problem with counting. But I need a condition that accounts for both simultaneously. When I give both conditions, it does not work and suggests and Error is [WB0027]:Expression has a syntax error.
Similarly, when I try to count the number of pregnancies that lasted between 0-31 days and happened only after 2011, I face a similar problem:
ros_preg.Count(x=>x.p220.InRange(0,31) && x=>x.p220AAy>2011)
I tried another expression, but it doesn’t work either
ros_preg.Count(x=>x.p220>0 && x=>x.p220<=31 && x=>x.p220AAy>2011)

Do you have suggestions how to correct the problem, please?

try the following:
ros_preg.Count(x=>(x.p220ABy>2011) && (x.p220AC>=5))
ros_preg.Count(x=>(x.p220>0) && (x.p220<=31) && (x.p220AAy>2011))

Fantastic, thanks so much! It accepted it.

I am glad to help. Regards, Sergiy

Dear Sergiy,

A similar question:

I need to enable section if a number of alive children from the roster for one woman is either above 0 or equal 0. However, it doesn’t accept the expressions.

The warning is - Operator > cannot be applied to operands of type bool and int.
Both q216 and p216 (child being alive) are categorical single select with a dichotomous choice of 1 (yes) and 2 (no).

ros.Count(x=>(x.q216==1)>0 || ros_preg.Count(x=>(x.p216==1)>0
ros.Count(x=>(x.q216==1)==0 || ros_preg.Count(x=>(x.p216==1)==0

I tried this, but still unsuccessful:

ros.Count(x=>(x.q216==1)>0) || ros_preg.Count(x=>(x.p216==1)>0)
ros.Count(x=>(x.q216==1)==0) || ros_preg.Count(x=>(x.p216==1)==0)

I am sure it is problem with parenthesis again but can’t figure out the correct combination. Suggestions are very welcome.

I suppose the fix could be to create a number of intermediate variables:
ros.Count(x=>(x.q216==1)>0
ros.Count(x=>(x.q216==1)==0
But it also gives an error: [WB0027]:Expression has a syntax error.

Any suggestions are very welcome, thank you beforehand.

Duplicate posting.
Solution posted and accepted in
http://support.mysurvey.solutions/customer/portal/questions/17091397
(#2890)