How can I sort pivot tables with aggregates?

I can’t sort the aggregates of the following pivot table:

a = {    {"Grupo5", 1, 2, 3}, {"Grupo1", 4, 5, 6}, {"Grupo5", 7, 6, 
    7}, {"Grupo2", 8, 9, 10}, {"Grupo2", 8, 9, 10} };
SortBy[  
 PivotTable[  
  Sort[   Tabular[  a , {"grupo", "num 1", "num 2", "num 3"}  ]   ],
  Length[\.08 #["num 1"]] &, "grupo", "num 2", 
  IncludeGroupAggregates -> True],
 #[[1]] &
   ]

Sort pivot tables.nb (11.6 KB)

I’m not sure if that’s what you were looking for, or not.

Thank you Lewis, but the code you sent is exactly the code I wrote with my question. My problem is that I want the column All (the Total) to be in the fire right column (the same as when you do a Pivot table in Excel).

Not exactly, my code places the group aggregates at the bottom of the table, granted, as you say, not at the right as you’re aiming for. Hopefully someone else can help with that.

Thank you Lewis. Now I see the difference. Very useful.

Ricardo, your passive aggression isn’t cool. That aside, what might actually be useful to you is this link: https://www.youtube.com/live/OKN297uHtkc?si=3qPoOxQUhHyizgFq&t=2130 Jon McLoone might have what you’re looking for.

Apologies Lewis. I truly appreciate the time you spent checking my code and suggesting improvements. For me it’s very useful to have different ways of approaching a problem. It is useful to know how I can sort in different ways. Your suggestions may not be a direct solution to the specific problem of aggregates in a pivot table, but they are useful in the use of other functions. Interacting with other members of the Wolfram Community is invaluable to me.

Thank you for sharing the video. I still haven`t finished watching it in detail, but I will, as soon as I have a chance, and will comment,

Thanks Ricardo.

Thanks Lewis. I think this solves the problem.