I have the following excel spreadsheet and I am trying to work out how I can write a formula in order to provide the values in column D. 

In each row, there is a test date, I am trying to calculate the day difference from each test date to the principal date, specific to each subject.

I assume this would involve selecting the principal test date based on the value in column C and I am not sure how I can do this.

Any help would be appreciated.

```
A            B           C                 D
Subject      TestDate    Principal date    Day difference from Principal  date
Subject 1    01/12/2014                    -3
Subject 1    02/12/2014                    -2
Subject 1    03/12/2014                    -1 
Subject 1    04/12/2014   Yes               0
Subject 2    07/12/2014                    -1
Subject 2    08/12/2014   Yes               0
Subject 2    11/12/2014                     3
Subject 3    17/12/2014                    -1
Subject 3    18/12/2014   Yes               0
Subject 3    24/12/2014                     6 

```