How to execute dynamic queries with visualisations

If you had all the information per document you could use scripted fields to do this calculation but as it is right now I don't think that this is possible.
I think that there is another discuss post about it Calculating one field from different documents