You will need to get the data ordered in the load scrip such that you can use Peek() function to determine when things have changed and do your check to see if next record requires the average etc. If you want to do things in the visualization, then Set Analysis is likely the only option I believe. Here are some links that may be helpful:
https://community.qlik.com/t5/Qlik-Design-Blog/Average-Which-average/ba-p/1466654
https://community.qlik.com/t5/Qlik-Design-Blog/A-Primer-on-Set-Analysis/ba-p/1468344
https://community.qlik.com/t5/Qlik-Design-Blog/Set-Analysis-in-the-Aggr-function/ba-p/1463822
https://help.qlik.com/en-US/qlikview/April2020/Subsystems/Client/Content/QV_QlikView/Scripting/load-...
About the best point in the right direction I have, hopefully helps a little.
Regards,
Brett
To help users find verified answers, please do not forget to use the "Accept as Solution" button on any post(s) that helped you resolve your problem or question.
I now work a compressed schedule, Tuesday, Wednesday and Thursday, so those will be the days I will reply to any follow-up posts.