Is this for Perspective or Vision? The solution will differ slightly depending on the answer.
For either, create a tag that will totalize or change value when a new critical alarm is added.
The basic approach for vision would likely be to use a client tag change event script. Use the tag mentioned above and use that as the driving tag for the change event script.
For perspective, create a custom session property (or view property if you want to restrict it to a specific view) and bind the value of the property to the above mentioned tag (or if the tag is an expression tag, use the same expression in a binding on the custom property)
For Vision:
For Perspective: