There are functions which will do this sort of thing, and I've used them on occasion.
But, the advantage (in my opinion) of doing it the way that I suggested is that the data analysis is more visible so that if there are any errors in your spreadsheet it's much easier to track down and correct.
G