| 
			
			 | 
		#1 | 
| 
			
			
			
			 Member 
			
			![]() Posts: 11 
				Karma: 10 
				Join Date: Dec 2020 
				
				
				
				Device: Kindle iOS App 
				
				
				 | 
	
	
	
		
		
			
			 
				
				Template: sum of multiple integers from other columns
			 
			
			
			Suppose in an attempt to better rate my books, I created 4 custom columns: 'story', 'characters', 'writing', 'ending', each an integer between 1-10. 
		
	
		
		
		
		
		
		
		
		
		
		
	
	Then I'd like to add another column called 'total_score', which is the sum of the above. How should I build the template? (General Program Mode is preferred, if possible) Thanks!!  | 
| 
		 | 
	
	
	
		
		
		
		
			 
		
		
		
		
		
		
		
			
		
		
		
	 | 
| 
			
			 | 
		#2 | 
| 
			
			
			
			 Member 
			
			![]() Posts: 11 
				Karma: 10 
				Join Date: Dec 2020 
				
				
				
				Device: Kindle iOS App 
				
				
				 | 
	
	
	
		
		
		
		
		 
			
			I tried something like:  
		
	
		
		
		
		
		
		
		
		
		
		
		
			program: field(#'story') + field(#'characters') + field(#'writing') + field(#'ending') which didn't work. I also tried program: add(x, y), but it only accept 2 arguments, which could work, but seems a little messy. Last edited by Quuzuu; 01-17-2021 at 03:52 AM.  | 
| 
		 | 
	
	
	
		
		
		
		
			 
		
		
		
		
		
		
		
			
		
		
		
	 | 
| 
			
			 | 
		#3 | 
| 
			
			
			
			 Member 
			
			![]() Posts: 11 
				Karma: 10 
				Join Date: Dec 2020 
				
				
				
				Device: Kindle iOS App 
				
				
				 | 
	
	
	
		
		
		
		
		 
			
			Update: my current solution (wonder if there's a cleaner way): 
		
	
		
		
		
		
		
		
		
		
		
		
	
	program: r = 0; r = add(r, field('#story')); r = add(r, field('#characters')); r = add(r, field('#writing')); r = add(r, field('#ending')); floor(r);  | 
| 
		 | 
	
	
	
		
		
		
		
			 
		
		
		
		
		
		
		
			
		
		
		
	 | 
| 
			
			 | 
		#4 | 
| 
			
			
			
			 Grand Sorcerer 
			
			![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,525 
				Karma: 8065948 
				Join Date: Jan 2010 
				Location: Notts, England 
				
				
				Device: Kobo Libra 2 
				
				
				 | 
	
	
	
		
		
			
			 
			
			In the next version of calibre (5.10 probably) add() and multiply() accept a variable number of arguments. Thus, once released your solution can be written as 
		
	
		
		
		
		
		
		
		
		
		
		
		
			Code: 
	program:
    floor(add(field('#story'), field('#characters'), field('#writing'), field('#ending')))
Last edited by chaley; 01-17-2021 at 07:00 PM. Reason: Correct mistaken function name  | 
| 
		 | 
	
	
	
		
		
		
		
			 
		
		
		
		
		
		
		
			
		
		
		
	 | 
| 
			
			 | 
		#5 | 
| 
			
			
			
			 Member 
			
			![]() Posts: 11 
				Karma: 10 
				Join Date: Dec 2020 
				
				
				
				Device: Kindle iOS App 
				
				
				 | 
	
	
	
		
		
		
		
		 
			
			Thanks so much!
		 
		
	
		
		
		
		
		
		
		
		
		
		
	
	 | 
| 
		 | 
	
	
	
		
		
		
		
			 
		
		
		
		
		
		
		
			
		
		
		
	 | 
![]()  | 
            
        
    
| Tags | 
| template | 
            
  | 
    
			 
			Similar Threads
		 | 
	||||
| Thread | Thread Starter | Forum | Replies | Last Post | 
| Showing template-computed columns as [rating] stars isn't possible? | kaoruAngel | Library Management | 2 | 11-06-2017 09:49 AM | 
| Need help in Custom Columns, template syntax, and rounding numbers | dennocoil | Calibre | 0 | 07-10-2017 04:24 PM | 
| Need more help with searching multiple columns at once | beckyt | Library Management | 3 | 06-19-2016 07:35 PM | 
| Request: template-making assistance for column built from other columns | iienderii | Library Management | 9 | 04-04-2016 11:27 PM | 
| Can I generate sum of column or columns? | GeekyGal | Calibre | 5 | 09-29-2011 08:32 PM |