Create a new column in your data called "Grouping" or something similar. Place into this column, on a row by row basis, which group each row belows. If you already have this data, you can make use of it.
Once you have this additional column, you can use this column in your "Rows" data. The matrix and table visuals will have a subtotal switch you can turn on.