Thank you Rebeca for your advice.
I have tried this method. I created a new table in this kind of key.
But I still have an issue and that is how do I summarize transactions for each "contract_id_customer_number_key"?
Remember that one single transaction row can refere to several "contract_id_customer_number_key".
I have many to many relations - one transaction row can be refered to many contracts, and one contract can be refered to many transactions.
If I try to do this with set analysis it does not work, since the dimensions in a chart can not be refered to in a set analysis. And building extremely nested "if...then", will just take the breath out of my server and my mind...
My current approach is to solve this in my script completely. Making a for each loop on my contracts and reading my entire statistics file for each contract. This takes time, since I have 650 contracts and around 9 million transaction rows for each contract. It currently takes 4 hours to do this, it works, but I doubt this is the bet solution.
I was hoping there was a solution with intervall match or something else so that I do not have to read all my statistics over and over again.