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:
About the best point in the right direction I have, hopefully helps a little.
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.