Referee
Both numbers are right. Here is what each one counts that the other doesn't. ✓ Adds up: 459 − 359 + 92 = 192, and both totals match the numbers on the overview. Every step comes from the two definitions: the date each one counts by, and what it filters out. Only counts can be compared this way; revenue adds up francs, not leads.
Appointments (Operations)
459
Leads invoiced (Finance)
192
Operations counts 267 more. 100 leads are in both.
Where the difference comes from
Counted by Operations only
-
Not invoiced yet−214
Show 5 examples
Lead Created Appointment Status Invoiced 3029 10.08.2026 03.09.2026 Held 3063 11.08.2026 04.09.2026 Held 3095 12.08.2026 05.09.2026 Held 3157 14.08.2026 04.09.2026 Held 3184 16.08.2026 08.09.2026 Held -
Invoiced after September−145
Show 5 examples
Lead Created Appointment Status Invoiced 3221 17.08.2026 06.09.2026 Held 01.10.2026 3242 18.08.2026 09.09.2026 Held 09.10.2026 3258 19.08.2026 03.09.2026 Held 01.10.2026 3322 21.08.2026 13.09.2026 Held 08.10.2026 3415 26.08.2026 12.09.2026 Held 08.10.2026
Counted by Finance only
-
Appointment before September+92
Show 5 examples
Lead Created Appointment Status Invoiced 2460 15.07.2026 05.08.2026 Held 01.09.2026 2664 24.07.2026 15.08.2026 Held 10.09.2026 2737 27.07.2026 15.08.2026 Held 03.09.2026 2750 28.07.2026 07.08.2026 Held 04.09.2026 2753 28.07.2026 14.08.2026 Held 01.09.2026
How it's calculated
Rows per step
with scoped as (
select lead_id, created_at, channel, canton, product, broker, appointment_at, appointment_status, contract_signed_at, invoiced_at, invoice_amount_chf,
coalesce((appointment_at >= timestamp '2026-09-01 00:00:00' at time zone 'Europe/Zurich' and appointment_at < timestamp '2026-10-01 00:00:00' at time zone 'Europe/Zurich'), false) and coalesce(appointment_status in ('scheduled', 'held'), false) as in_a,
coalesce((invoiced_at >= timestamp '2026-09-01 00:00:00' at time zone 'Europe/Zurich' and invoiced_at < timestamp '2026-10-01 00:00:00' at time zone 'Europe/Zurich'), false) as in_b
from leads
where (appointment_at >= timestamp '2026-09-01 00:00:00' at time zone 'Europe/Zurich' and appointment_at < timestamp '2026-10-01 00:00:00' at time zone 'Europe/Zurich')
or (invoiced_at >= timestamp '2026-09-01 00:00:00' at time zone 'Europe/Zurich' and invoiced_at < timestamp '2026-10-01 00:00:00' at time zone 'Europe/Zurich')
),
classified as (
select scoped.*,
case when in_a and not in_b then case when invoiced_at is null then 'minus:time_null'
when invoiced_at < timestamp '2026-09-01 00:00:00' at time zone 'Europe/Zurich' then 'minus:time_before'
when invoiced_at >= timestamp '2026-10-01 00:00:00' at time zone 'Europe/Zurich' then 'minus:time_after'
else 'minus:filter' end
when in_b and not in_a then case when appointment_at is null then 'plus:time_null'
when appointment_at < timestamp '2026-09-01 00:00:00' at time zone 'Europe/Zurich' then 'plus:time_before'
when appointment_at >= timestamp '2026-10-01 00:00:00' at time zone 'Europe/Zurich' then 'plus:time_after'
else 'plus:filter' end
when in_a then 'both'
else 'neither' end as bucket
from scoped
),
stepped as (
select s.step, classified.*
from classified
cross join lateral (values (case when in_a then 'start' end),
(case when in_b then 'end' end),
(bucket)) as s(step)
where s.step is not null
)
select step, count(*) as n
from stepped
group by step
order by stepExamples per step
with scoped as (
select lead_id, created_at, channel, canton, product, broker, appointment_at, appointment_status, contract_signed_at, invoiced_at, invoice_amount_chf,
coalesce((appointment_at >= timestamp '2026-09-01 00:00:00' at time zone 'Europe/Zurich' and appointment_at < timestamp '2026-10-01 00:00:00' at time zone 'Europe/Zurich'), false) and coalesce(appointment_status in ('scheduled', 'held'), false) as in_a,
coalesce((invoiced_at >= timestamp '2026-09-01 00:00:00' at time zone 'Europe/Zurich' and invoiced_at < timestamp '2026-10-01 00:00:00' at time zone 'Europe/Zurich'), false) as in_b
from leads
where (appointment_at >= timestamp '2026-09-01 00:00:00' at time zone 'Europe/Zurich' and appointment_at < timestamp '2026-10-01 00:00:00' at time zone 'Europe/Zurich')
or (invoiced_at >= timestamp '2026-09-01 00:00:00' at time zone 'Europe/Zurich' and invoiced_at < timestamp '2026-10-01 00:00:00' at time zone 'Europe/Zurich')
),
classified as (
select scoped.*,
case when in_a and not in_b then case when invoiced_at is null then 'minus:time_null'
when invoiced_at < timestamp '2026-09-01 00:00:00' at time zone 'Europe/Zurich' then 'minus:time_before'
when invoiced_at >= timestamp '2026-10-01 00:00:00' at time zone 'Europe/Zurich' then 'minus:time_after'
else 'minus:filter' end
when in_b and not in_a then case when appointment_at is null then 'plus:time_null'
when appointment_at < timestamp '2026-09-01 00:00:00' at time zone 'Europe/Zurich' then 'plus:time_before'
when appointment_at >= timestamp '2026-10-01 00:00:00' at time zone 'Europe/Zurich' then 'plus:time_after'
else 'plus:filter' end
when in_a then 'both'
else 'neither' end as bucket
from scoped
),
stepped as (
select s.step, classified.*
from classified
cross join lateral (values (case when in_a then 'start' end),
(case when in_b then 'end' end),
(bucket)) as s(step)
where s.step is not null
)
select step, lead_id, created_at, channel, canton, product, broker, appointment_at, appointment_status, contract_signed_at, invoiced_at, invoice_amount_chf
from (
select stepped.*, row_number() over (partition by step order by lead_id) as rn
from stepped
where step not in ('both', 'neither')
) ranked
where rn <= 5
order by step, lead_idAppointments (Operations)
select count(distinct lead_id) as value
from leads
where appointment_at >= timestamp '2026-09-01 00:00:00' at time zone 'Europe/Zurich'
and appointment_at < timestamp '2026-10-01 00:00:00' at time zone 'Europe/Zurich'
and appointment_status in ('scheduled', 'held')Leads invoiced (Finance)
select count(distinct lead_id) as value
from leads
where invoiced_at >= timestamp '2026-09-01 00:00:00' at time zone 'Europe/Zurich'
and invoiced_at < timestamp '2026-10-01 00:00:00' at time zone 'Europe/Zurich'
The app runs these queries with parameters; here the values are written in, so they can be read or pasted into psql.