|  01-17-2021, 12:22 AM | #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!! | 
|   |   | 
|  01-17-2021, 02:49 AM | #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 02:52 AM. | 
|   |   | 
| Advert | |
|  | 
|  01-17-2021, 03:05 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); | 
|   |   | 
|  01-17-2021, 09:18 AM | #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 06:00 PM. Reason: Correct mistaken function name | 
|   |   | 
|  01-17-2021, 04:35 PM | #5 | 
| Member  Posts: 11 Karma: 10 Join Date: Dec 2020 Device: Kindle iOS App | 
			
			Thanks so much!
		 | 
|   |   | 
| Advert | |
|  | 
|  | 
| 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 08:49 AM | 
| Need help in Custom Columns, template syntax, and rounding numbers | dennocoil | Calibre | 0 | 07-10-2017 03:24 PM | 
| Need more help with searching multiple columns at once | beckyt | Library Management | 3 | 06-19-2016 06:35 PM | 
| Request: template-making assistance for column built from other columns | iienderii | Library Management | 9 | 04-04-2016 10:27 PM | 
| Can I generate sum of column or columns? | GeekyGal | Calibre | 5 | 09-29-2011 07:32 PM |