This is going to be a bit complicated, and I don't have a walkthrough handy (mostly b/c I haven't done it myself), but we have docs on stat creation available
here and
here to help you along.
We are planning on adding things like standard deviation to the normal set of tools available but I don't know when it will be added.