What you need is an OQL query, so you can use Group By.
For example:
select creation_date, count(*)
from painting
group by creation_date
having <your condition> (optional)
You could have a look at the OQL module in the appstore.
Or maybe look for charts based on (OQL) Datasets. I don’t know if they exist.
First thought: I don’t think you can group by creation date because dates are a point in time. So this would give you one record for each painting (unless by some chance more than one painting was created at the exact same millisecond)
Beyond that, the answer depends on how many paintings you have in the database. If its a small number (say less than 1000), your method is probably fine.
For a larger dataset, you can do this using database retrieves. Here is how I would do this:
The first retrieve:
Get earliest year
Get current year
Retrieve shipments in the current year
Change Variable
I think that would do it, without having to loop through all paintings.
Hope that provides some food for thought.
Mike