Issue with setting date to previous month using DATEPART

I am struggling with a formula. I am trying to put the date to the first of the previous month. For example if the date is 1/12018 I want to return 12/1/2017. If it's 2/1/2018 I want 1/12018. The formula looks correct to me but I keep getting an error:

"Operation failed. Label: Lookup XXXX_membership, Name: XXXX_membershipLookup, Message: Invalid Argument function DatePart, parameter 1, value interval: Error in calling Operation Query (Lookup Block) "

IF( DATEPART("m",CapHistory.CAPMO)=1, 12, DATEPART("m",CapHistory.CAPMO)-1 )   

&"/01/" & IF( DATEPART("m",CapHistory.CAPMO)=1, DATEPART("y",CapHistory.CAPMO)-1,  DATEPART("y",CapHistory.CAPMO))



(3) Answers