Filter with subqueries

Hi all,
I have a Redshift database with incremental inserts so I catch the lateste log cod with a subquerie and the rank function like this:
select p.brand, sum(p.value)
from (select t.*, rank() over ( partition by itep_cod
order by logp_cod desc) as rk
from itenspedidos t) p
where rk = 1
and {{data}}
and {{chanel}}

The filters don’t work because of the subqueries. Is there any way to make the filters work?
Thanks in advance!