You are viewing limited content. For full access, please sign in.

Question

Question

Tables - Want SUM of each row!

asked on September 5, 2017

Last time you'll all hear from me tonight, I promise...

Currently, I have a table set up on my Form whereby I can fill out time (daily) spent on a given project each week. Subsequent rows (if the user adds them) will give you another project you can fill your daily time in (Sunday > Saturday). And so on and so forth.

The problem is... I want a total at the end of each of those rows. It's easy enough to get the SUM of that row using variables and using a SUM calculation on that total field, but then when I add a second row, it continues to total up all fields, rather than just what is in that row! It's driving me a bit crazy. I've attached a picture of the table, and anything you can do to help is greatly appreciated!

My current calculation, in case you're curious or it helps, is...

=SUM(Time.Sun, Time.Mon, Time.Tues, Time.Wed, Time.Thurs, Time.Fri, Time.Sat)

 

Example.PNG
Example.PNG (9.92 KB)
0 0

Answer

SELECTED ANSWER
replied on September 6, 2017
$(document).ready(function () {
  $(document).on('blur', '#q5 tr td input[type="text"]', function(){
  	var columns = ['Sun.','Mon.','Tues.','Wed.','Thurs.','Fri.','Sat.'];
  	$('#q5 tr').each(function() {
    	var sum = 0;
    	$(this).find('td').each(function() { 
  			if(columns.indexOf($(this).attr('data-title')) > -1){
              if($(this).find('input[type="text"]').val() =='')
              {
                $(this).find('input[type="text"]').val(0.00).change();
              }
         		sum = sum + parseFloat($(this).find('input[type="text"]').val());
        	}
    	});
      $(this).find('td[data-title="Total:"] input[type="text"]').val(sum).change();
  	});
  });
});

Hey, this isn't the nicest code i've ever written but should form a basis for how to do it in javascript.

I don't like using the built in sums in the table personally so I tend to fall back on javascript.

Just change the #q5 to what ever your table selector is and you should be good to go.

 

hope it helps :)

1 0
replied on September 6, 2017

You are the freaking man! Haha... thank you so much, worked like a charm!

1 0

Replies

replied on September 6, 2017

Hello ,

 

If you are using the latest version of forms (10.2.1) you don't need to write the script, you can use this function

=SUM(INDEX(Table.Column_1, ROW()),INDEX(Table.Column_2, ROW()),INDEX(Table.Column_3, ROW()),INDEX(Table.Column_4, ROW()),INDEX(Table.Column_5, ROW()))

 

replacing the column names.

 

Regards,

 

4 0
You are not allowed to follow up in this post.

Sign in to reply to this post.