'WHERE clause limiting results to 50 days from birth date using DATEADD

I'm trying to get weights of patients for their first 50 days of life. I've tried to filter using DATEADD in the where clause, but it keeps returning rows outside of the 50 day range.

The dates used are in different tables- birthdate is in the patient table, datevalue in the date table. Datevalue is the date a weight was entered into a flowsheet.

SELECT
    FlowsheetRowDim.Name,
    FlowsheetRowDim.DisplayName,
    FlowsheetValueFact.Value,
    PatientDim.LastName,
    PatientDim.PrimaryMrn,
    PatientDim.BirthDate,
    DateDim.DateValue 
FROM FlowsheetValueFact
JOIN PatientDim ON FlowsheetValueFact.PatientDurableKey = PatientDim.DurableKey AND PatientDim.IsCurrent = '1' 
JOIN DateDim ON FlowsheetValueFact.DateKey = DateDim.DateKey
JOIN FlowsheetRowDim ON FlowsheetValueFact.FlowsheetRowKey = FlowsheetRowDim.FlowsheetRowKey AND FlowsheetRowDim.DisplayName = 'Weight'
JOIN TimeOfDayDim ON FlowsheetValueFact.TimeOfDayKey = TimeOfDayDim.TimeOfDayKey
WHERE PatientDim.PrimaryMrn ='xxxxxxx' AND DateDim.DateValue >= DATEADD(day,-50, PatientDim.BirthDate)


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source