Postgres - How to get Multi-Count Query using a Where Clause for a Join Table
It looks like you can use COUNT(DISTINCT expression), so I'd try replacing

count(distinct eo.orderlineid) as orderline,


with this

COUNT(DISTINCT CASE WHEN     o.deliveryrequesteddate &gt;= '2018-03-06'
                         and o.deliveryrequesteddate &lt;= '2018-05-06'
                 THEN eo.orderlineid
                 ELSE NULL
               END) as orderline,


NULL values are not counted by COUNT, and the DISTINCT should still ensure you're only counting each orderlineid once.