Check out the OOTB Project Manager Schedule Dashboard portlet - which is a 'drill-down' portlet. You could get the 'TOP LEVEL' section to also grab the required totals from the projects (in your case the top level will be the portfolio category column).
It does mean the NSQL is reading the data twice (once for each of the projects, and once for the portfolio level), so you need to also consider performance.
I haven't worked out how to make the totals go at the bottom (like in your spreadsheet), so the totals will be at the top, prior to each portfolio.
You also indicate you are on V12.1, so apologies in advance if the suggested portlet is not in this old version.