The past perfect tense is used to describe an action (or event) that happened before another action (or event) happened. The past perfect is formed by combining the past tense of the helping verb have with the past participle of the verb.
(subject) had (not) + past participle
He had gone to the store
We had visited our parents
I hadn't worked for this company
A complete sentence using the past perfect tense combines a clause formed with the past perfect tense plus a clause formed with the past simple tense. (Review how to form the past simple by reading this post.)
The two clauses are most often joined with the conjunction before, but others can be used, such as when and by the time.
(subject) had + past participle + before + past simple
I had worked for this company for five years before you started.
I had worked for this company for five years by the time you started.
I had worked for this company for five years when you started.
The order of the two clauses doesn't matter because the action described using the past perfect tense is always the first action and the action described using the simple past tense is always the second action.
Before you started, I'd worked for this company for five years.
When forming questions, the subject is placed after the helping verb had (not).
had (subject) + past participle + before + past simple ?
Had you eaten before I cooked dinner?
Had you been to New York before you went last year?
How many times had you fixed your car before it finally broke down?
Why hadn't you cleaned your room before I got home?