With Rollup can be replaced with Rollup
SELECT
Product_Name,
Scheme_Name,
Invest_Amount,
broker_commission,
-1 AS IsSchemeTotal,
-1 as IsGrandTotal
FROM @GroupTest
Union ALL
select
isnull(Product_Name, 'ZProductTotal'),
isnull(Scheme_Name,'ZTotal'),
sum(Invest_Amount),
SUM(Broker_Commission),
GROUPING(Scheme_Name) AS IsSchemeTotal,
GROUPING(Product_Name) AS IsGrandTotal
from @grouptest
group by rollup (Product_Name,Scheme_Name)
ORDER BY Product_Name,
Scheme_Name,
IsSchemeTotal,
IsGrandTotal
To give the same results