Register your plugin on Post create of Subgrid entity –
First retrieve Entity A guid from Target context and then use below.
Now in you plugin logic, you will use fetchxml to find count of the records and then update the count in Entity A.
Subgrid entity will have Entity A lookup.
What if Record is getting deleted from subgrid, do you want to again update the count?
If yes then you may have to write code to do that
Please mark my answer verified if this is helpful!
Follow my Blog: xrmdynamicscrm.wordpress.com/