Writing expression

Our questionnaire has a question that record the amount of contribution paid for the National Pension Fund (3% of basic salary) by the household . This question is normally related these two questions:

  • Do you contribute to the National Pension Scheme? (Yes or No)
  • Basic Salary (Amount)

Now, each household member who answered ‘yes’ to question a) is required to provide an amount for the NPF contribution which will be 3% of his/her basic salary. Kindly note that, the maximum amount for a household member to contribute NPF is 254 irrespective of the amount of his/her basic salary.

What have been done so far?

Create a long integer variable type (name: basic_3)

Expression: (long)Math.Min(Math.Ceiling(( basicSalary??0) * 0.03), 524)

Create a long integer variable type (name: total_basic_3)

Expression: members.Sum(x => x.basic_3 ?? 0)

Create a string variable (name: basic_3_str)

Expression: string.Join(", ", members.Select(x => $"{x.rowname}: 3% = {x.basic_3}").ToArray()) + $". Total: {total_basic_3}"

Create the NPF variable (name: npf)

Question text: Life insurance and pension contributions of which <i>National Pension Fund</i>. From basic salary: %basic_3_str%

Validation: labourRoster.Any(x=>(x.contributePension ?? 0) ==1 )? self > 0 : true

The Result
image
The issue is that it displayed all the members whether they are entitled and not for the NPF contribution. In the case, above only the household member Tom was entitled for the contribution. Therefore, it will be grateful if you could please assist us with the codes, to restrict the household members only to those who are entitled to pay for the NPF contribution.

1 Like

Dear bharati,

I have several questions/recommendations:

  1. Why do you ask the last question 6.2.18i in the first place? Do you want the enumerator to enter the total amount of contributions to the NPF, in this case 1048? This does not make sense/is not necessary given you have obtained this information already and computed it in the software ( total_basic_3).

  2. If you would like to display the information of total_basic_3, use a static text, which also gives you the opportunity to display it in a nice manner with paragraphs etc.

  3. In any case, if you would like to adjust your displayed text to only display those members that actually contribute to the fund (q1 == “Do you contribute to the National Pension Scheme?” ), revise basic_3_str to:

    string.Join(", “,members.Where(x=>x.q1==1).Select(x => $”{x.rowname}: 3% = {x.basic_3}").ToArray()) + $". Total: {total_basic_3}"

Best
Peter

2 Likes

Thank you very much Peter. Indeed it works well but there is an issue regarding the total.

image

It seems that the total 1048, still sum the NPF contribution for all members of the household who are are entitled and not for this particular contribution. I have tried to modify the total_basic_3. Unfortunately it is not working. Please could you help with this issue.

Well regarding your comment on the question 6.2.18i, I understand your point of view, but unfortunately the question cannot be removed as this questionnaire is approved by the Board. Yes, it is required by the enumerator to enter the total, but we are trying to facilitate his/her work by displaying the calculated figures.

Regarding the static text, I wanted to ask if it is possible to display information in a tabular form?

Regards,
Bharati

Dear Bharati,

I can not recreate the problem you encounter.

total_basic_3 == members.Select(x=>x.basic_3).Sum() even though your syntax should work as well.

Do you have basicSalary enabled only if q1==1?

In doubt, adjust also total_basic_3 to
members.Where(x=>x.q1==1). select(y=>y.basic_3).Sum()

With respect to the static text:
First of all, you could display the total separately from basic_3_str, therefore delete the last part “Total: {total_basic_3}” in your string variable.

In the static text you could write:
%basic_3_str%
< br>< br>
This amounts to a total Household contribution of: %total_basic_3%.

If you also would like to show the respective household members contribution below each other: Spontaneously I only could suggest a quick and dirty approach:
Create several variables based on basic_3_str with the syntax of

string.Join(", “, hhroster.Where(x=>x.q1==1).Select(x => $”{x.rowname}: 3% = {x.basic_3}").ToArray()[0]) for variable basic_3_str1

and

string.Join(", “, hhroster.Where(x=>x.q1==1).Select(x => $”{x.rowname}: 3% = {x.basic_3}").ToArray()[1]) for variable basic_3_str2

and so forth…
In the static text you write:
Contributions by the HH to the fund:
%basic_3_str1%
< br>< br>
%basic_3_str2%
< br>< br>



This amounts to a total Household contribution of: %total_basic_3%.

A bit dirty, maybe someone else knows a better way.

Cheers
Peter

2 Likes

Thank you for your kindly support. The codes worked perfectly.

With respect to the static text, it is observed that one is required to create a certain number of variables basic_3_str1, basic_3_str2… beforehand and which normally need to be greater than the number of household members.

Regards
Bharati

Yap. My “dirty” proposed solution implied that you create around 8 or so variables through which you should cover most households I suspect (I assume children can not provide to the fund…). But again, its quite static and there are probably “cleaner” solutions.

Just to add: Use a validation condition for 6.2.18i that it must equal the calculated total (or at least close to it). If this information is that important to you, you also could ask a question to the respondent about how much in total they approximately paid to the fund which you again could use to validate 1) the salary responses and the 2) fund contributions.

Cheers

In this questionnary, https://designer.mysurvey.solutions/questionnaire/details/953faa24e13144ac984e1ad62593aab5/chapter/ec2b645984236ab19bbffeeed7e8c8f5/static-text/63b7f445835442c8ab48dcbc122ac4c0
in the section “Text decoration”, on the third static text you can find this
image

Copy and paste those gray points in your variable "basic_3_str"

And this could be help you to show the data in tabular mode
image

This could be a way.

1 Like

Thank you very much Peter and kv700032

1 Like

@peterbrueckmann

Is it possible add another validation check to the expression:

Say for instance:
members.Where((x=>x.contributePension==2).Select(y => y.basic_2).Sum()

Tried but it isn’t working:
members.Where((x=>x.establishmentName.InRange(2,4))&& contributePension==2).Select(y => y.basic_2).Sum()

Could you please help on this matter

Regards,
Bharati

1 Like

I think you are missing the second directive in the syntax at contributePension as well as a bracket too much:

members.Where(x=>x.establishmentName.InRange(2,4) && x.contributePension==2).Select(y => y.basic_2).Sum()

Give it a try.

Best
Peter

2 Likes

Thank you!!! It works perfectly

Regards
Bharati

1 Like