title: Summing query results based on another column in Google Spreadsheets
body: <p>Hi I have this sample sheet: <a href="https://docs.google.com/spreadsheets/d/1TzKlEAF5IcZehmyyRUQ5ELE63Q-ZVfp9Nfx5-zvKAOc/edit?usp=sharing" rel="nofollow noreferrer">https://docs.google.com/spreadsheets/d/1TzKlEAF5IcZehmyyRUQ5ELE63Q-ZVfp9Nfx5-zvKAOc/edit?usp=sharing</a></p>
  
  <p>I want to pull the data from the left chart. Then I want to sum Same companies revenues. Then I want to put that data dynamically to the right part. I also want to be able to check how much revenue I got from each company each month. I also want to see top 5 companies who made purchase in each month.</p>
  
  <p>So for example: If Company A made 3 purchases in January I want to see sum of these purchases next to company name and sort companies from highest money to lowest for each month.</p>
  
  <p>I wrote a function for that but it doesn't work.</p>