periodOverPeriodDifference for workdays

Hi

Thank you for the logic. But I am getting error when I tried the below formula

ifelse (extract(‘WD’, {Range_Date})=2,
periodOverPeriodDifference(max({Range_Count}),{Range_Date},‘DAY’,3),
periodOverPeriodDifference(max({Range_Count}),{Range_Date},‘DAY’,1))

Error message “Mismatched aggregation. Custom aggregations can’t contain both aggregated and nonaggregated fields, in any combination.”
at
periodOverPeriodDifference(max({Range_Count}),{Range_Date},‘DAY’,3),

Can you please help me understand what I have missed here.