Sum each repeat row

nbradshaw

Active Member
I am struggling with this...I have searched dozens of forum posts but I cannot figure this out....and even the wiki pages.

I simply need to add each repeat element and place the sum in 'Totals'. JS or calc is fine with me.

Repeat element names:
project_time_tracker_407_repeat___monday
project_time_tracker_407_repeat___tuesday
project_time_tracker_407_repeat___wednesday
project_time_tracker_407_repeat___thursday
project_time_tracker_407_repeat___friday
project_time_tracker_407_repeat___saturday
project_time_tracker_407_repeat___sunday
project_time_tracker_407_repeat___subtotal <------ ( repeat row total)
 

Attachments

  • repeat_calc.JPG
    repeat_calc.JPG
    70.4 KB · Views: 39
Ok...got it done with calc element...didn't realize it was that easy...

Code:
$monday = '{project_time_tracker_407_repeat___monday_raw}';
$tuesday = '{project_time_tracker_407_repeat___tuesday_raw}';
$wednesday = '{project_time_tracker_407_repeat___wednesday_raw}';
$thursday = '{project_time_tracker_407_repeat___thursday_raw}';
$friday = '{project_time_tracker_407_repeat___friday_raw}';
$saturday = '{project_time_tracker_407_repeat___saturday_raw}';
$sunday = '{project_time_tracker_407_repeat___sunday_raw}';
$total = (int)($monday + $tuesday + $wednesday + $thursday + $friday + $saturday + $sunday);
return $total;
 
Probably better to cast each individual placeholder. If any of them are empty, that code would break with a syntax error.

Code:
return (int)'{project_time_tracker_407_repeat___monday_raw}'
+ (int)'{project_time_tracker_407_repeat___tuesday_raw}'
+ (int)'{project_time_tracker_407_repeat___wednesday_raw}'
+ (int)'{project_time_tracker_407_repeat___thursday_raw}'
+ (int)'{project_time_tracker_407_repeat___friday_raw}'
+ (int)'{project_time_tracker_407_repeat___saturday_raw}'
+ (int)'{project_time_tracker_407_repeat___sunday_raw}';

-- hugh
 
Thanks Hugh, Is there an easy way to SUM the Totals column? Either in the same repeat group on a non-repeat group? I found some php examples and calc examples...but I really need an AJAX method so that the SUM will update as they put their time in. Suggestions?
 
Did you try enabling Ajax for a calc? Won't work in same repeat group, but I think it should work for an element outside a repeat, summing an element from inside a repeat.

Sent from my HTC6545LVW using Tapatalk
 
We are in need of some funding.
More details.

Thank you.

Members online

Back
Top