To make it a bit clearer this would be the SQL for just one date: select xsd2xld(22/04/2021) as Cnt_Date, count(*) as Cnt from (select id, max(date_status_added) as last_date from reg_history_all where not id in(select id from reg_history_all where reg_status = 'Deceased') and date_status_added < xsd2xld(22/04/2021) group by id having reg_status = 'Registered') xsd2xld is just a function converting to the Excel date. RBS