What I want to achieve is based pretty much on this solution but with the sum and a category text per category. So instead of writing
[% aggregate( 'layer','sum',"category_txt", filter:="category_txt"='a' and "name" = @atlas_pagename)%] category a
[% aggregate( 'layer','sum',"category_txt", filter:="category_txt"='b' and "name" = @atlas_pagename)%] category b
...
[% aggregate( 'layer','sum',"category_txt", filter:="category_txt"='n' and "name" = @atlas_pagename)%] category n
in a textbox in print composer I suspect some nested array aggregation function beeing capable of doing so but I am new to this kind of syntax. So what I have done so far to achieve this is to create a virtual layer named 'num_category_txt' using this query:
SELECT count(*) as num, category_txt, name
FROM layer
GROUP BY name, category_txt
And the corresponding expression in print composer looks like this:
[% aggregate( 'num_category_txt','concatenate',"num"||' '||"category_txt", filter:="name" = @atlas_pagename, concatenator:='\n')%]
This is a functional work around but I wonder how to do this directly in a (nested?) aggregate function.