This is Max from the Shopify Team.
Have you considered trying a different approach? The Shopify Analytics section (Analytics > Reports) could be of great use to you. There is a Retail sales by product report that might be just what you're after!
Take a look and let us know if that helps.