I have a custom information column with this template, maybe you can adapt it and see if it works for you.
Code:
python:
def evaluate(book, context):
# Use the built-in template function to format the title and authors
x = context.funcs.template('{Title} - {authors}')
# Count the books in the series. First get the series name
series = book.get('series')
if series:
# The book is in a series. Get the book count in that series
db = context.db.new_api
series_id = db.get_item_id('series', series)
book_count = len(db.books_for_field('series', series_id))
# Add the number of books to the title - author string
x = x + f' - From the series "{series}, which has {book_count} books {"s" if book_count > 1 else ""}'
else:
x = x + " - This book does not belong to a series"
return x