Virtual column reverting to zero value

In filling in a questionnaire, we have a legacy real column which used to be where the user would select either “Pas compris” or “Bien compris”, however we now want this column to be calculated based on the responses to various Y/N questions.

We created a virtual column which would do the summation of these boolean fields, and then do a calculation based on how many were answered “TRUE”. This calculation should then be shown as a percentage to the user, and populate the above real column with the result (where if the score is >90% it shows “Bien compris”, otherwise “Pas compris”.

When you fill the questionnaire, if calculated the % correctly, however the app syncs it resets to 0%. If you edit the record, the correct value comes back, but again once it syncs the view shows 0%. Is this because the virtual columns are calculating in the wrong order, or something else?

Formulas from bottom 3 rows:

  1. if([Contract_Check_Result]>0.9,“Bien Compris”,“Pas Compris”)

  2. (
    

    IF([q1]=true,1,0)+
    IF([q2]=true,1,0)+
    IF([q3]=true,1,0)+
    IF([q4]=true,1,0)+
    IF([q5]=true,1,0)+
    IF([q6]=true,1,0)+
    IF([q7]=true,1,0)+
    IF([q8]=true,1,0)+
    IF([q9]=true,1,0)
    )

  3. [Contract_Check_Calculation]/9


    Thanks!

Instead of deviding with 9, please devide it with 9.0 and then the result will be a decimal and the correct percentage value is shown.

3 Likes

Hi Aleksi,

Many thanks, this worked. Is this because of some conversion issue between number and percent type?

Nothing to do with the percentage. The same result will happen if you try to calculate like 4/8. The result will be 0. You need to use decimal as a divider if you want to have result as a decimal. 4/8.0 will give you 0.5

2 Likes

I’ve done more searching and found similar issues others have faced with the number / decimal type, so apologies for not finding those before. What I do find confusing here is that the app showed the correct value up until the app was synced, and then it showed the behaviour you mention. Does the calculation change somehow?

1 Like

When the form is opened, the calcualtion is made on client side and when you sync the app, your virtual column is calculated on server side. That’s why are seeing the change when the data is synced.

3 Likes
2 Likes