This tense is also called the Past Perfect Continuous and is formed as:
had + been + V-ing. (V=Verb)
I/we/they/you/he/she/it had been V-ing (=I’d, we’d, they’d, you’d, he’d, she’d, it’d been V-ing)
Questions are formed as:
Had + subject+ been + V-ing ?
Short answers are formed as:
Yes, he/she/it/we/you/they had. No, he/she/it/we/you/they hadn’t.
The Past Perfect Progressive is the past equivalent of the Present Perfect Progressive and is used for:
1) a past action of certain duration which had visible results in the past.
They were wet because they had been walking in the rain. [1, p.13]
2) emphasis on the duration of an action which started and finished in the past before another past action or a stated time in the past.
She had been working as a clerk for 10 years before she resigned. [1, p.13]
3) actions started in the past and continuing up to a certain event in the past.

Sources:
- Evans, V. and Doodley, J. (2011). New Round-Up 5. Pearson Education Limited.
- LET’S LEARN!. (2018). Past Perfect Continuous. [online] Available at: https://letslearnenglisheasy.weebly.com/past-perfect-continuous.html [Accessed 8 Oct. 2018].