So not able to see anything directly broken in your code by eye and as you mention it works for the most part. But get effected by making the dataset larger what you are looking at is most likely the fact you no where wait for the data to be ready.
When looking at the API you will see sentences like this
$w("#myDataset").onReady( () => {
if you place this in the giveFilter() and in the onready() your waiting for the dataset to be ready before anything happens. If this does not work there is a similiar approach to repeater.