title: SSRS Top N for Dates
body: <p>So I am currently writing an SSRS report which I want to calculate lead time based on an arbitrary number deliveries.</p>
  
  <p>I have my query in SSRS but now I would like to filter it to show the last 5 deliveries. Usually I would use a Top N for filtering but SSRS rightly complains that the number 5 is not a date.</p>
  
  <p>How do you filter the last five latest dates without knowing the exact dates of the records you are returning?</p>
  
  <p>Dataset is as follows (lead time is a calculation of order date less delivery date)</p>
  
  <pre><code>Order | Del_Date   | Lead_Time
  ------|------------|-----------
  00001 | 2015-05-01 | 20
  00002 | 2015-01-08 | 21
  00003 | 2015-02-05 | 22
  00004 | 2015-03-11 | 26
  00005 | 2015-01-21 | 8
  00006 | 2015-04-12 | 12
  00007 | 2015-03-02 | 12
  00008 | 2015-02-01 | 12
  </code></pre>
  
  <p>The query should return</p>
  
  <pre><code>Order | Del_Date   | Lead_Time
  ------|------------|-----------
  00001 | 2015-05-01 | 20
  00003 | 2015-02-05 | 22
  00004 | 2015-03-11 | 26
  00006 | 2015-04-12 | 12
  00007 | 2015-03-02 | 12
  </code></pre>
  
  <p>Thanks,</p>