View Single Post
Old 10-04-2022, 04:07 PM   #2
allanahk
Connoisseur
allanahk ought to be getting tired of karma fortunes by now.allanahk ought to be getting tired of karma fortunes by now.allanahk ought to be getting tired of karma fortunes by now.allanahk ought to be getting tired of karma fortunes by now.allanahk ought to be getting tired of karma fortunes by now.allanahk ought to be getting tired of karma fortunes by now.allanahk ought to be getting tired of karma fortunes by now.allanahk ought to be getting tired of karma fortunes by now.allanahk ought to be getting tired of karma fortunes by now.allanahk ought to be getting tired of karma fortunes by now.allanahk ought to be getting tired of karma fortunes by now.
 
allanahk's Avatar
 
Posts: 71
Karma: 2202292
Join Date: Nov 2018
Device: Kobo Libra 2
Hi there, I have a custom column which essentially does what you're asking - it's True if the book is either standalone or first in series (even if the series index doesn't begin at 1) and False otherwise. I find it useful to have this info in a column (called #first_in_series) so I can search very easily (either #first_in_series:=True or False). Here are the steps:

1. Preferences - Advanced - Tweaks - set "allow_template_database_functions_in_composit es = True"

2. Add column - column built from other columns (see attached pic)

3. Copy this code into the column template:

Code:
program: 
# Returns True if it is the first book in a series (or a standalone book with no series), including cases where the series index does not begin at 1. 
# Returns False otherwise

first_in_series = 'True';

if field('series') then 
	this_series = field('series');
	this_series_index = field('series_index');
	books_in_series = book_values('title', 'series:="' & this_series & '"', ',', 0);
	
	lowest_series_num = 999;
	for title in books_in_series:
		title_index = book_values('series_index', 'title:="' & title & '"', ',', 0);
		if title_index < lowest_series_num then
				lowest_series_num = title_index
		fi
	rof;	
	
	if lowest_series_num !=# this_series_index then
		first_in_series = 'False'
	fi
fi;

output = first_in_series
Attached Thumbnails
Click image for larger version

Name:	temp.PNG
Views:	114
Size:	19.5 KB
ID:	196984  
allanahk is offline   Reply With Quote