title: Custom calculation for sold amount
body: <p>I have the following table </p>
  
  <pre><code>;WITH cte AS(
  SELECT * FROM (VALUES
  ('23/06/2014', 3,  0,  11203659),
  ('30/06/2014', 7,  1,  11203659),
  ('07/07/2014', 6,  0,  11203659),
  ('14/07/2014', 2,  1,  11203659),
  ('21/07/2014', 5,  0,  11203659),
  ('28/07/2014', 21, 1,  11203659),
  ('04/08/2014', 3,  1,  11203659),
  ('11/08/2014', 9,  1,  11203659),
  ('18/08/2014', 7,  0,  11203659),
  ('25/08/2014', 4,  0,  11203659),
  ('01/09/2014', 2,  0,  11203659),
  ('08/09/2014', 4,  0,  11203659),
  ('15/09/2014', 1,  0,  11203659),
  ('22/09/2014', 3,  1,  11203659),
  ('29/09/2014', 6,  1,  11203659),
  ('06/10/2014', 3,  1,  11203659),
  ('13/10/2014', 4,  1,  11203659)
  ) as t([Date], SoldAmt, promo, code_article))
  </code></pre>
  
  <p>I try to calculate average sum (SoldAmt)/number od days between the min date and max date rolling back the first 28 days/times in which promo =1 by Article </p>
  
  <pre><code>select sum(SoldAmt)/convert(day, Date)
  from MyTable 
  group by [code article ],Date
  </code></pre>