To answer your last question, in chart expression, you can know which dimension you are working on by using Dimensionality(). The leftmost dimension is 1, the one after that is 2 etc.
Based on this, you can create a if condition to get what you want. In your case, for months you want the sum of ages but for year you want the age of the last month of the year. Your expression will be