Body: <p>I want to create a list of products and show how many times a product has been sold in a certain period. But how? I'll dived into the topProduct widgets and there they use a custom querie.</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-06-19T00:06:33.877Z
Comments.Text: Do you want to create it in control panel? Anyway, i dont think it will be acomplished by just one query. You might want to query orders of specific date range, then check what line items these orders had, get purchasables of this line items, (variant), and finally get product belonging to variant. And then count number of occurences of these products. For large number or orders this most likely be not very performant.
Comments.UserDisplayName: Piotr Pogorzelski
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-06-20T13:32:15.137Z
Comments.Text: It is for the control panel indeed. Preformance was also my concern. A custom query is a better idea. But have to found out how create it.
Comments.UserDisplayName: Maarten Heideman
Tags: <plugin-craftcommerce3>
Title: How query the total sales of a selection of products in a specific time range in Craft Commerce?
ThreadText: # How query the total sales of a selection of products in a specific time range in Craft Commerce?
  
  (Asked by: username_0 on 2022-06-17)
  
  I want to create a list of products and show how many times a product has been sold in a certain period. But how? I'll dived into the topProduct widgets and there they use a custom querie.
  
  **Tags:** plugin-craftcommerce3
  
  > **Comments:**
  > **username_1**: Do you want to create it in control panel? Anyway, i dont think it will be acomplished by just one query. You might want to query orders of specific date range, then check what line items these orders had, get purchasables of this line items, (variant), and finally get product belonging to variant. And then count number of occurences of these products. For large number or orders this most likely be not very performant.  
  > **username_0**: It is for the control panel indeed. Preformance was also my concern. A custom query is a better idea. But have to found out how create it.  
  
  ---
  
  ## 0 answers
  
  