I'd start by creating a subquery that creates/calculates the relevant absences, and then do the calc on that.
This will give you the EFFECTIVE start and end dates and EFFECTIVE duration of each event in the period:
Code:
SELECT
TA.StaffID,
TA.AbsenceType,
IIF(TA.AbsenceStartDate >= Date() - 365,
TA.AbsenceStartDate,
Date() - 365
) As AbsenceStartDate,
TA.AbsenceStartDate + TA.AbsenceLength As AbsenceEndDate,
IIF(TA.AbsenceStartDate >= Date() - 365,
TA.AbsenceLength,
Int(TA.AbsenceStartDate + TA.AbsenceLength - Date() + 365)
) AS AbsenceLength
FROM
tblAbsence AS TA
WHERE TA.AbsenceType="sick"
AND TA.AbsenceStartDate + TA.AbsenceLength >= Date() - 365;
The Count of those records is the count of the events. The sum of the absenceLength is the total duration within the last year.
Then Join to the tblStaff table to get the name. You don't need to group by the names, just accept the first one or max or min, since they're all the same for each staffID.
Not sure why you wanted the AbsenceStartdate, or which of the possible dates that you really wanted. I'm going to give you the earliest start and latest end dates.
So, your Bradford calc should look somewhat like this:
Code:
SELECT
TS.StaffID,
First(TS.Surname) As Surname,
First(TS.Forename) As Forename,
Count(TA2.AbsenceLength])*Count(TA2.AbsenceLength])*Sum(TA2.AbsenceLength) AS BradFordFactor,
Min(TA2.AbsenceStartDate) AS FirstAbsence,
Max(TA2.AbsenceEndDate) AS LastAbsence
FROM
tblStaff AS TS
INNER JOIN
(SELECT
TA.StaffID,
TA.AbsenceType,
IIF(TA.AbsenceStartDate >= Date() - 365,
TA.AbsenceStartDate,
Date() - 365
) As AbsenceStartDate,
TA.AbsenceStartDate + TA.AbsenceLength As AbsenceEndDate,
IIF(TA.AbsenceStartDate >= Date() - 365,
TA.AbsenceLength,
Int(TA.AbsenceStartDate + TA.AbsenceLength - Date() + 365)
) AS AbsenceLength
FROM tblAbsence AS TA
WHERE TA.AbsenceType="sick"
AND TA.AbsenceStartDate + TA.AbsenceLength >= Date() - 365
) AS TA2
ON TS.StaffID = TA2.StaffID
GROUP BY
TS.StaffID;