if condition value_if_true else value_if_false is the ternary operator in Python and you can use it in any expression, elif is a statement that cannot be used in an expression.
If you want to use more complex expressions you can use the example from @p.colbert or create a pick_the_right_value() function and use that, by entering the function in the databinding, something like self.pick_the_right_value(self.item)
Thanks so much for the guidance. I had never realized that functions were directly accessible through data bindings. This completely changes how I look at customization options. Although @p.colbert’s solution was the direct answer to my question, your functions within databindings solution is both the answer to my question as well as the answer to questions I hadn’t even considered. Thanks again.
A pattern I frequently use in this circumstance is to create a property and bind to that. Whatever logic is required sits within the property body and the data binding line becomes very simple.
The only problem with properties is that the automatic data binding with the key of DataGrid columns expects dictionary or dictionary-like objects, so I always derive my classes from the AttributeToKey class described here.
Data binding on most components can be any of these (considering self.item is a box of cookies):
# full expression in data binding
sum(1 for c in self.item.cookies if cookie.color == 'red']
# pre-calculated value in dictionary
self.item["n_red_cookies"]
# property that calculates the value
self.item.n_red_cookies
Driving a class from AttributeToKey allows to use n_red_cookies as the key on DataGrid columns.