BEGIN and END format in awk

I'm new to awk, trying to understand the basics.
I'm trying to reset the counter everytime the program gets a new file to check.
I figured in the BEGIN part it would work, but it doesn't.

#!/bin/awk -f
BEGIN   {counter=0}
          {
                sum=0
                for ( i=1; i<=NF; i++)
                {
                        sum += $i
                }
                if ( sum == copy)
                {
                        counter += 1
                }
                copy=sum
        }
END   {
        counter+=1
        print counter
        if(counter == NR)
        {
                print FILENAME " " "YES" " " sum
        }
        else
        {
                print FILENAME " " "NO" " " sum
        }
}

Would appreciate your help.

Note that a BEGIN block is executed once only before the first input record is read.

So this block is not called for each input file if there are several input files for your awk program.

You could do something like:

FNR == 1 {
             counter = 0
}

to reset your counter for each input file.