I counted the number of people who were there before us.
I counted how many people were there before us.
どちらの言い方も間違いではないですが、
I counted how many people were there before us.
という場合の there は「そこに」という場所を表しています。
それに対し、there were は「いた・あった」を意味しているので、there were at 場所 とする方が自然です。
ーI counted how many people there were at XX before us.
「XXで私たちの前に何人いたか数えた」
私なら次のように言うでしょう。
ーI counted the number of people who were there before us.
「私たちの前に何人いたか数えた」
ご参考まで!