The Past Perfect Continuous Tense is used to describe:
1. something that started at some point in the past, continued for a period of time up to a certain point in the past, and was still in progress when another action took place.
a. I had been living in Chicago for three years when all my families decided to migrate to the US in 2013.
I started living in Chicago 3 years earlier (in 2010). I continued to live in the city up to 2013, and was still living there, when my families migrated to the US.
b. Rita had been waiting for half an hour when I finally arrived.
Rita started to wait half an hour earlier than my arrival, continued to wait up to my arrival time.
The Past Perfect Continuous Tense vs The Past Continuous Tense
The past perfect continuous tense is related to the past continuous tense. The past perfect continuous tense is focused on the duration of your action, i.e. for two hours, for a few minutes, for a week, etc. However, if you DO NOT INCLUDE the duration of time, the past continuous tense is used. The past continuous tense is focused on your action being in progress when another action interrupted.
2. cause and effect relation. look at the following examples.
a. I was so tired because I had been working too hard.
b. All my body got dirty. I had been playing in the mud.
c. I felt sick. I had been eating too much.