List calculations...

I saw the list calculations for Columns... is there a way to total row values for particular groups? I have two groups with Radio button values... would like to total for each record. Would this be done with a Calc field in the form and list that calc field in the list? or is there a way to total a group of fields within a group for each record (row)?
 
I think you can just set the sum calculation 'split on' option to the radio button element.
 
That seems to set it for calculating a Column Sum... not fields sum.

Sum_Split_on.png

I have a series of Radio Button Questions where the responder selects one of seven responses giving a value of 1 - 7

There are 15 total questions So I want to add each question to a sum total of points scored. I have split the questions into two groups.

Once the Form is completed I want to be able to show a score of the given ratings. The sum would contain a range of the lowest being 15 points... Highest being 105 Points.

Radio_Button_Values.png

Not sure how this would accomplish what I need.. Below is the group breakout of the form.

Form_with_Radio_Buttons.png I would also want to add to an overall total the third group of Goals and Objectives Scoring showing the totals in the Employee Summation Section and Employee Information tabs
 
woops sorry I missed this thread :(
I presume all the questions are on the same form?
If so, yes you would need a calculation element with some code similar to :

PHP:
$fields = array('mylist___question1');
$total = 0;
foreach ($fields as $field)
{
  $value = JArrayHelper::getValue($data, $field . '_raw', array());
  $thisSum = array_sum($value);
  $total += $thisSum;
}
 
return $total;

Add the radio buttons full names you want to sum on to the $fields array

e.g.

PHP:
$fields = array('mylist___question1', 'mylist___question2');
 
Thanks Rob! Yes they are on the same form... So I could put this total on any part of the form in real time and it would total what has been entered so far>
 
if you want realtime then you would need to set the cal element to use 'ajax' otherwise its calculated upon submission.
 
Does that mean I will need a calc element in each group of form or can I have one calc element for the entire form?


Kind of depends what exactly you are trying to do. If I'm reading your description right, you only want a single 'total', which totals up a number of different radio button values. In which case, you only need one calc element, which (as per Rob's instructions) has an array of all the radio button element names you want to include in the total.

-- hugh
 
Thanks... Just making sure... I do want a group total for one of the groups which is added to the two previous groups of Radio button questions .so I am thinking I would need a calc element in that group only... with a total for the over all form group that would total the the first two groups... then a final calc element for the calculation for adding the two group total with the final group total to get the overall calculated total
 
I have something wrong... I am just getting a total of 0 on this calc when all radio buttons have been used...

$ratings = array('trec_employee_appraisal___trec_ti_value', 'trec_employee_appraisal___trec_ar_value',

'trec_employee_appraisal___trec_sk_value', 'trec_employee_appraisal___trec_so_value',

'trec_employee_appraisal___trec_ed_value', 'trec_employee_appraisal___trec_ap_value',

'trec_employee_appraisal___trec_dk_value', 'trec_employee_appraisal___trec_dt_value',

'trec_employee_appraisal___trec_sa_value', 'trec_employee_appraisal___trec_mi_value',

'trec_employee_appraisal___trec_ds_value', 'trec_employee_appraisal___trec_cm_value',

'trec_employee_appraisal___trec_sl_value', 'trec_employee_appraisal___trec_md_value',

'trec_employee_appraisal___trec_tg_value');
$total1 = 0;
foreach ($ratings as $rating)
{
$value = JArrayHelper::getValue($data, $rating . '_raw', array());
$thisSum = array_sum($value);
$total1 += $thisSum;
}

return $total1;
___________________________________________________________
Just got a 0 displayed in the form but in the table I see a value of 59... so I know the calculation is working but not displaying on the form
 
ok the script needed tweaking to work for both form submission calculations and for when the list is rendered (as the values are no longer in arrays but returned as strings):

I've altered it on your site (I had to set our user to be a Manager to be able to add and test - hope thats ok!)

the code is :

PHP:
$ratings = array('my_list___question1', 'my_list___question2');
$total1 = 0;
 
foreach ($ratings as $rating)
{
  $value = JArrayHelper::getValue($data, $rating . '_raw', array());
  $thisSum = is_array($value) ? array_sum($value) : $value;
  $total1 += $thisSum;
}
 
return $total1;
 
Well thank you! So the above code is for the list calc or does both? Does it store value in record or just recalculates during list view?
 
Its the code to go in a calculation element. It will save to the db when the form is submitted, and if I remember correctly it will calculate the results for display purposes when the list is shown in the browser.
 
We are in need of some funding.
More details.

Thank you.

Members online

No members online now.
Back
Top