I am trying to figure out an array formula to calculate a running balance within the categories listed in another column.

Here is an example sheet for reference
<https://docs.google.com/spreadsheets/d/1kmitZF6YtARAi2EB0NggbIhKgsb7tLCknsKBTEKycrw/edit?usp=sharing>

The requirements are:

* Running balance to be calculated on `Amount` column
* Running balance should be calculated based on the `Category` column. I.e. Amounts under category A should only count towards the running balance of A
* The running balance should be calculated based on values sorted by the ascending `Date` column. Even though entries may appear in the sheet unsorted.

Any help would be much appreciated!!