My experience was that it was always 1 floor before the boss floor. I count the room where the actual boss fight is as it's own separate floor. So, the actual floor that the treasure hall usually appeared for me, might be counted differently than how you count or interpret the levels.
In your example, (from my perspective) the answer is to use the key on the 7th floor, because when you advance to floor 8, you are thrown into the boss encounter.
You might be looking at the dungeons as having 8 floors, with the boss fight on the 8th floor. In that case, the treasure hall would appear on the 8th floor.
As I mentioned in my post, you can click on the treasure key at any time. You don't need to be on 1 specific floor. So, if you enter a dungeon with 10 floors (where the 10th floor is the boss fight), you can click on the treasure key on floor 1,2,3,4,5,6,7,8,9, and even floor 10.
The game will only consume one of your treasure keys if there is a treasure hall on that particular floor. If there is no treasure hall on a particular floor, the game will tell you that it didn't do anything and the number of keys you have will remain the same.
You are not going to miss out on something and 'lose your chance at a treasure hall' if you are on 'the wrong floor'. So, feel free to click on that key any time you want, to check and see if a particular floor has a hidden entry to a treasure hall.