Duration before a past event: I had been waiting for two hours before the bus finally arrived.
Cause and effect in the past: He was exhausted because he had been working all day.
Repeated actions over time: She had been practicing the piano every day before the recital.
Theory of Past Perfect Continuous (British Council)
Past Perfect Continuous 1 (Perfect English Grammar)
Past Perfect Continuous 2 (English Club)
Past Perfect Continuous Vs. Past Simple (Perfect English Grammar)
Past Perfect Simple Vs. Continuous (English Page)
Maria's Ride and Extreme Sports, Reading (BBC Learning)