Hi Jernej @JernejHenigman ,
I think the following calc will get you what you are looking for.
sum((<measure> - avgOver(<measure>,[<groupField>],PRE_AGG))^2, [<groupField>])
If this doesn’t get you there, due to nuances in your data, please add a sample analysis in Arena with sample data and expected results so that community can help you further.
Regards,
Arun Santhosh
Pr Quick Sight SA