Register Guidelines E-Books Today's Posts Search

Go Back   MobileRead Forums > E-Book Software > Calibre > Library Management

Notices

Reply
 
Thread Tools Search this Thread
Old 11-12-2019, 12:15 AM   #1
tamarissa
Connoisseur
tamarissa began at the beginning.
 
Posts: 56
Karma: 10
Join Date: Aug 2018
Device: Kobo Aura H2O
Composite Column based on Multiple Criteria

I'm looking to create a custom column based on information from 2 other columns. The end result I'm looking for is:

IF Column A (#keep_read) = "Yes" & Column B (#read_status) = "N",
THEN Column C (#send_kobo) = "Yes"
ELSE Column C (#send_kobo) = "No"

I can't figure out how to adapt any of the "If-then-else" formulas for multiple columns . Or maybe there's a better option; as along as it works!
tamarissa is offline   Reply With Quote
Old 11-12-2019, 08:35 AM   #2
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 12,421
Karma: 8012664
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Try this
Code:
program:
	strcmp(
		field('#keep_read'), 'yes', 
		'No',
		strcmp(
			field('#read_status'), 'N',
			'No',
			'Yes',
			'No'),
		'No')
This one works too.
Code:
program:
	test(
		and(
			strcmp(field('#keep_read'), 'yes', '', 1, ''),
			strcmp(field('#read_status'), 'N', '', 1, '')
		), 
		'Yes',
		'No');
chaley is offline   Reply With Quote
Advert
Old 11-12-2019, 10:20 AM   #3
tamarissa
Connoisseur
tamarissa began at the beginning.
 
Posts: 56
Karma: 10
Join Date: Aug 2018
Device: Kobo Aura H2O
Thanks, but I tried both of those and they both resulted in a template error.
tamarissa is offline   Reply With Quote
Old 11-12-2019, 10:25 AM   #4
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 12,421
Karma: 8012664
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by tamarissa View Post
Thanks, but I tried both of those and they both resulted in a template error.
They both work for me.
  1. Check that the column names are spelled correctly.
  2. Check the parentheses.
  3. Don't put any other characters in the template.
  4. Ensure that the keyword "program" is at the absolute beginning of the template.
  5. Do not intermix {...} templates with "program mode" templates.
  6. Post exactly what you tried.
chaley is offline   Reply With Quote
Old 11-12-2019, 10:31 AM   #5
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 12,421
Karma: 8012664
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Also, use the "Template Tester" to debug the template. The process goes much faster. Put the tester on the main library context menu (Preferences / Toolbars & menus / The context menu for books in the calibre library.
chaley is offline   Reply With Quote
Advert
Old 11-12-2019, 06:01 PM   #6
tamarissa
Connoisseur
tamarissa began at the beginning.
 
Posts: 56
Karma: 10
Join Date: Aug 2018
Device: Kobo Aura H2O
I did get it work, shut everything down and restarted; it seemed to be fine. However, it doesn't do what it says it should; for example, there are multiple books that have the Read Status column = "N" that should say have the new column say "yes", but actually says "no'.

Last edited by tamarissa; 11-12-2019 at 06:23 PM. Reason: Add photo
tamarissa is offline   Reply With Quote
Old 11-12-2019, 06:06 PM   #7
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 12,421
Karma: 8012664
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by tamarissa View Post
Where is the template tester? I don't see anywhere in the program, and google that didn't provide any further information.
You get the template tester into the main library context menu in the way I said in my last post.
Quote:
Also, use the "Template Tester" to debug the template. The process goes much faster. Put the tester on the main library context menu (Preferences / Toolbars & menus / The context menu for books in the calibre library.
Then when you right click on a book, one option presented to you will be the template tester.
chaley is offline   Reply With Quote
Old 11-12-2019, 06:24 PM   #8
tamarissa
Connoisseur
tamarissa began at the beginning.
 
Posts: 56
Karma: 10
Join Date: Aug 2018
Device: Kobo Aura H2O
See Screenshot:
Attached Thumbnails
Click image for larger version

Name:	Screen Shot 2019-11-12 at 4.18.42 PM.png
Views:	72
Size:	94.0 KB
ID:	174872  
tamarissa is offline   Reply With Quote
Old 11-12-2019, 06:30 PM   #9
tamarissa
Connoisseur
tamarissa began at the beginning.
 
Posts: 56
Karma: 10
Join Date: Aug 2018
Device: Kobo Aura H2O
There are also books that in the Keep Read column say yes, but it still says no in new column.
Attached Thumbnails
Click image for larger version

Name:	Screen Shot 2019-11-12 at 4.18.42 PM.png
Views:	73
Size:	94.0 KB
ID:	174873  
tamarissa is offline   Reply With Quote
Old 11-12-2019, 06:34 PM   #10
tamarissa
Connoisseur
tamarissa began at the beginning.
 
Posts: 56
Karma: 10
Join Date: Aug 2018
Device: Kobo Aura H2O
I've just confirmed this with both options; the only result provided is "No".
Attached Thumbnails
Click image for larger version

Name:	Screen Shot 2019-11-12 at 4.28.46 PM.png
Views:	66
Size:	30.2 KB
ID:	174874  
tamarissa is offline   Reply With Quote
Old 11-13-2019, 06:33 AM   #11
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 12,421
Karma: 8012664
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Not sure what to say. It works for me.

I used the following template (same as above)
Code:
program:
	test(
		and(
			strcmp(field('#keep_read'), 'yes', '', 1, ''),
			strcmp(field('#read_status'), 'N', '', 1, '')
		), 
		'Yes',
		'No');
and these column definitions:
Click image for larger version

Name:	Clipboard01.jpg
Views:	76
Size:	24.7 KB
ID:	174886

Click image for larger version

Name:	Clipboard03.jpg
Views:	70
Size:	29.7 KB
ID:	174887

Click image for larger version

Name:	Clipboard05.jpg
Views:	65
Size:	39.0 KB
ID:	174889

The next screen capture shows the input data and the result. There is exactly one "Y", which is the correct answer (as far as I know).
Click image for larger version

Name:	Clipboard04.jpg
Views:	61
Size:	14.7 KB
ID:	174888

---

For completeness I also tried it with #keep_read as a text column with the following definition.
Click image for larger version

Name:	Clipboard06.jpg
Views:	66
Size:	27.3 KB
ID:	174890

The following screen capture shows that the template still works.
Click image for larger version

Name:	Clipboard07.jpg
Views:	63
Size:	17.6 KB
ID:	174891

---

All I can suggest is that you check that:
  • you didn't change the template
  • the column definitions are the same as mine
  • the data is as you described (the same as mine).

This test template might help you work out where things are going wrong. It shows the result of the two strcmp functions.
Code:
program:
	strcat(
		'keep_read strcmp returns "',
		strcmp(field('#keep_read'), 'yes', '', 1, ''),
		'", read_status strcmp returns "',
		strcmp(field('#read_status'), 'N', '', 1, ''),
		'"')
chaley is offline   Reply With Quote
Old 11-13-2019, 08:12 AM   #12
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 12,421
Karma: 8012664
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
Quote:
Originally Posted by tamarissa View Post
I did get it work, shut everything down and restarted; it seemed to be fine. However, it doesn't do what it says it should; for example, there are multiple books that have the Read Status column = "N" that should say have the new column say "yes", but actually says "no'.
This post implies that you want the following:
Code:
IF Column A (#keep_read) = "Yes" OR Column B (#read_status) = "N",
THEN Column C (#send_kobo) = "Yes"
ELSE Column C (#send_kobo) = "No"
The "&" says that both conditions must be true in order to see "Yes" (the meaning of "and"). This post implies that "Yes" should be displayed if either condition is true (the meaning of "or").

If I am right then you can fix the problem by changing "and(" in the template to "or(".
chaley is offline   Reply With Quote
Old 11-19-2019, 07:12 PM   #13
tamarissa
Connoisseur
tamarissa began at the beginning.
 
Posts: 56
Karma: 10
Join Date: Aug 2018
Device: Kobo Aura H2O
I was able to spend a bunch of time this weekend and managed to follow all your instructions and get everything working properly, so thank you so much. It did need an 'OR', not an 'AND'... I should have thought of that since I run into that issue in Excel sometimes

If I could get one more piece of advice though, I'd really appreciate it... I thought it would be very easy to add one more useful piece of criteria to the code, but it keeps telling me it needs a closing parenthesis, but doesn't say where. As far as I can tell, they are all closed.

Code:
program:
	test(
		or(
			strcmp(field('#keep_read'), 'yes', '', 1, ''),
			strcmp(field('#keep_read'), 'series incomplete' '', 1, ''),
			strcmp(field('#read_status'), 'N', '', 1, '')
		), 
		'Yes',
		'No');
Thanks
Attached Thumbnails
Click image for larger version

Name:	Screen Shot 2019-11-19 at 5.04.00 PM.png
Views:	70
Size:	96.3 KB
ID:	175025  
tamarissa is offline   Reply With Quote
Old 11-20-2019, 05:31 AM   #14
chaley
Grand Sorcerer
chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.chaley ought to be getting tired of karma fortunes by now.
 
Posts: 12,421
Karma: 8012664
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
The problem is one that gets me frequently. The error handling bits of the template parser are not very good , so the parser can get very confused. It isn't really the parens that are unbalanced but is instead a missing comma.

The corrected template is below with missing comma is in large font bold.

Code:
program:
	test(
		or(
			strcmp(field('#keep_read'), 'yes', '', 1, ''),
			strcmp(field('#keep_read'), 'series incomplete', '', 1, ''),
			strcmp(field('#read_status'), 'N', '', 1, '')
		), 
		'Yes',
		'No');
Glad you got it working.
chaley is offline   Reply With Quote
Reply


Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Need help with composite column BookJunkieLI Library Management 2 07-03-2019 11:42 AM
Can't search on custom column, multiple criteria bob.f Calibre Companion 0 03-19-2018 10:38 AM
Composite Column BetterRed Calibre 12 09-01-2013 04:58 AM
Composite column or not ? Bertrand Library Management 3 08-24-2011 01:27 AM
Custom Composite Column silentguy Calibre 4 11-24-2010 10:28 AM


All times are GMT -4. The time now is 04:45 PM.


MobileRead.com is a privately owned, operated and funded community.