Dynamic row groups in a matrix

Hi All !
I want to show row groups as hierarchy levels and need the sub total values belongs to each group and sub group levels. But the most important point is that my top next top group (from child to parent ) is not static its dynamic.i.e for a diffrent senario my under displayed example can have Universe--->Earth as parent for Australia and USA.

eg:
1.Australia
|-------> Sydney
|-------> Melbourne
2.USA
|------> North US
~~~~~~~~~|------> North US(1)
~~~~~~~~~|------> North US(2)
|------> South US
~~~~~~~~~|------> South US(1)
~~~~~~~~~|------> South US(2)

("~~~~~~~~~~~~" I had given for showing hierarchy )

Can I get some help from anybody for making a dynamic row groups in the matrix.
Waiting for a kind help.