Determine Order Streak
As mustaccio pointed out this is a "gaps and islands" problem:

declare @date date = '2020-01-16';


with ct as
(
    /* First you must detect the gaps, filtering those rows lesser than the selected date */
    select
        OrderDate,
        case when 
            datediff(day, 
                     coalesce(lag(OrderDate) over (order by OrderDate), OrderDate),
                     OrderDate
                     ) &lt;&gt; 1 then 1 else 0 end rst
    from
        orders
    where
        OrderDate &lt;= @date
)
, ct2 as
  (
      /* Then set an island of each group */
      select
          OrderDate,
          sum(rst) over (order by OrderDate) as grp
      from 
          ct
   )
   /* And finally count the affected rows */
   select top 1
       count(OrderDate) streak
   from
       ct2
   group by
       grp
   order by
       max(OrderDate) desc;




| streak |
| -----: |
|      5 |



db&lt;>fiddle here