"select count(1)" performance in a CTE
I think your query can be written using window aggregates. I don't know if it will be more efficient though:

with seekResults as
(
  select distinct
    trx_id_fk,
    account_fk
    customer_cif,
    customer_tin,
    tin_type,
    id_number,
    search_number
  from transactionsOP 
) 
select 
  trx_id_fk,  
  case 
    when account_fk is not null then
      count(*) over (partition by search_number, account_fk) 
    when customer_cif is not null then
      count(*) over (partition by search_number, customer_cif) 
    when customer_tin is not null then
      count(*) over (partition by search_number, customer_tin, tin_type)
    when id_number is not null then
      count(*) over (partition by search_number, id_number)
    else 
      count(*) over (partition by search_number)
  end as transaction_period
from seekResults ;