Example data (revised to include negative values - see comment of @ydd)
data =
<|"France" -> <|"18" -> -103.7`, "19" -> -103.9`, "20" -> -104.1`,
"21" -> -104.6`, "22" -> -105.`|>,
"Greece" -> <|"18" -> 96.6`, "19" -> 96.5`, "20" -> 96.4`,
"21" -> 96.`, "22" -> 94.1`|>,
"Italy" -> <|"18" -> -102.2`, "19" -> -101.1`, "20" -> -100.8`,
"21" -> -100.1`, "22" -> -99.7`|>,
"Portugal" -> <|"18" -> 97.3`, "19" -> 97.2`, "20" -> 97.4`,
"21" -> 97.4`, "22" -> 97.9`|>,
"Spain" -> <|"18" -> 100.4`, "19" -> 101.`, "20" -> 101.8`,
"21" -> 102.`, "22" -> 102.`|>,
"Total" -> <|"18" -> 88.4`, "19" -> 89.7`, "20" -> 90.7`,
"21" -> 90.7`, "22" -> 89.3`|>|>;
data // Dataset
I sometimes import data tables with column totals already appended. If I want to ReverseSort
this data by the last column, the total row must of course stay in place. Therefore:
sorted = <|ReverseSortBy[Last] @ data[[;; -2]], KeyTake[Last @ Keys @ data] @ data|>;
sorted // Dataset
Although I can live with this not too complicated solution, I'm curious to know if there isn't a more direct approach, which wouldn't deconstruct and reassemble the matrix.
SubsetMap
? $\endgroup$