|
|
#1 |
|
Connoisseur
![]() Posts: 58
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!
|
|
|
|
|
|
#2 |
|
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,525
Karma: 8065948
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')
Code:
program:
test(
and(
strcmp(field('#keep_read'), 'yes', '', 1, ''),
strcmp(field('#read_status'), 'N', '', 1, '')
),
'Yes',
'No');
|
|
|
|
|
|
#3 |
|
Connoisseur
![]() Posts: 58
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.
|
|
|
|
|
|
#4 | |
|
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,525
Karma: 8065948
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
|
|
|
|
|
|
|
#5 |
|
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,525
Karma: 8065948
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.
|
|
|
|
|
|
#6 |
|
Connoisseur
![]() Posts: 58
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 |
|
|
|
|
|
#7 | ||
|
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,525
Karma: 8065948
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
Quote:
|
||
|
|
|
|
|
#8 |
|
Connoisseur
![]() Posts: 58
Karma: 10
Join Date: Aug 2018
Device: Kobo Aura H2O
|
See Screenshot:
|
|
|
|
|
|
#9 |
|
Connoisseur
![]() Posts: 58
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.
|
|
|
|
|
|
#10 |
|
Connoisseur
![]() Posts: 58
Karma: 10
Join Date: Aug 2018
Device: Kobo Aura H2O
|
I've just confirmed this with both options; the only result provided is "No".
|
|
|
|
|
|
#11 |
|
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,525
Karma: 8065948
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');
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). --- For completeness I also tried it with #keep_read as a text column with the following definition. The following screen capture shows that the template still works. --- All I can suggest is that you check that:
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, ''),
'"')
|
|
|
|
|
|
#12 | |
|
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,525
Karma: 8065948
Join Date: Jan 2010
Location: Notts, England
Device: Kobo Libra 2
|
Quote:
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"
If I am right then you can fix the problem by changing "and(" in the template to "or(". |
|
|
|
|
|
|
#13 |
|
Connoisseur
![]() Posts: 58
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');
|
|
|
|
|
|
#14 |
|
Grand Sorcerer
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Posts: 12,525
Karma: 8065948
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');
|
|
|
|
![]() |
|
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 |