Yes
Since we're in May this year it's a good month to test and the prior month April:
Code:
SELECT dbo_v030mbrshp01PdMembers.MemberGroup, dbo_v030mbrshp01PdMembers.MemberType, IIf(Sum(IIf((DatePart("m",[PaymentDate])=4 Or DatePart("m",[PaymentDate])=5) And DatePart("yyyy",[paymentdate])=(DatePart("yyyy",Date())-1),1,0))=0,Null,Sum(IIf(DatePart("m",[PaymentDate])>=4 And DatePart("m",[PaymentDate])<=5,1,0))) AS May, IIf(Sum(IIf(DatePart("m",[paymentdate])>=4 And 5 And DatePart("m",[paymentdate])<=6,1,0))=0,Null,Sum(IIf(DatePart("m",[paymentdate])>=4 And 5 And DatePart("m",[paymentdate])<=6,1,0))) AS Jun, IIf(Sum(IIf(DatePart("m",[PaymentDate])>=4 And 5 And DatePart("m",[PaymentDate])<=7,1,0))=0,Null,Sum(IIf(DatePart("m",[PaymentDate])>=4 And 5 And DatePart("m",[PaymentDate])<=7,1,0))) AS Jul, IIf(Sum(IIf(DatePart("m",[PaymentDate])>=4 And 5 And DatePart("m",[PaymentDate])<=8,1,0))=0,Null,Sum(IIf(DatePart("m",[PaymentDate])>=4 And 5 And DatePart("m",[PaymentDate])<=8,1,0))) AS Aug, IIf(Sum(IIf(DatePart("m",[PaymentDate])>=4 And 5 And DatePart("m",[PaymentDate])<=9,1,0))=0,Null,Sum(IIf(DatePart("m",[PaymentDate])>=4 And 5 And DatePart("m",[PaymentDate])<=9,1,0))) AS Sep, IIf(Sum(IIf(DatePart("m",[PaymentDate])>=4 And 5 And DatePart("m",[PaymentDate])<=10,1,0))=0,Null,Sum(IIf(DatePart("m",[PaymentDate])>=4 And 5 And DatePart("m",[PaymentDate])<=10,1,0))) AS Oct, IIf(Sum(IIf(DatePart("m",[PaymentDate])>=4 And 5 And DatePart("m",[PaymentDate])<=11,1,0))=0,Null,Sum(IIf(DatePart("m",[PaymentDate])>=4 And 5 And DatePart("m",[PaymentDate])<=11,1,0))) AS Nov, IIf(Sum(IIf(DatePart("m",[PaymentDate])>=4 And 5,1,0))=0,Null,Sum(IIf(DatePart("m",[PaymentDate])>=4 And 5,1,0))) AS [Dec], IIf(Sum(IIf(DatePart("m",[PaymentDate])>=4 And 5 Or DatePart("m",[PaymentDate])<=1,1,0))=0,Null,Sum(IIf(DatePart("m",[PaymentDate])>=4 And 5 Or DatePart("m",[PaymentDate])<=1,1,0))) AS Jan, IIf(Sum(IIf(DatePart("m",[PaymentDate])=2,1,0))=0,Null,Sum(IIf(DatePart("m",[PaymentDate])>=4 And 5 Or DatePart("m",[PaymentDate])<=2,1,0))) AS Feb, IIf(Sum(IIf(DatePart("m",[PaymentDate])=3,1,0))=0,Null,Sum(IIf(DatePart("m",[PaymentDate])>=4 And 5 Or DatePart("m",[PaymentDate])<=3,1,0))) AS Mar, IIf(Sum(IIf(DatePart("m",[PaymentDate])=4 And DatePart("yyyy",[paymentdate])=DatePart("yyyy",Date()),1,0))=0,Null,Sum(IIf(DatePart("m",[PaymentDate])>=4 And 5 Or DatePart("m",[PaymentDate])<=4,1,0))) AS Apr, dbo_v030mbrshp01PdMembers.PaymentDate
FROM dbo_v030mbrshp01PdMembers
WHERE (((dbo_v030mbrshp01PdMembers.MemberTypeID)=1 Or (dbo_v030mbrshp01PdMembers.MemberTypeID)=2 Or (dbo_v030mbrshp01PdMembers.MemberTypeID)=4))
GROUP BY dbo_v030mbrshp01PdMembers.MemberGroup, dbo_v030mbrshp01PdMembers.MemberType, dbo_v030mbrshp01PdMembers.PaymentDate
HAVING (((dbo_v030mbrshp01PdMembers.PaymentDate) Between IIf(Month(Date())<=5,DateSerial(Year(Date())-1,5,1),DateSerial(Year(Date()),5,1)) And IIf(Month(Date())<=6,DateSerial(Year(Date()),5,30),DateSerial(Year(Date())+1,5,30))))
ORDER BY dbo_v030mbrshp01PdMembers.PaymentDate;
April:
Code:
IIf(Sum(IIf((DatePart("m",[PaymentDate])=3 Or DatePart("m",[PaymentDate])=4) And DatePart("yyyy",[paymentdate])=(DatePart("yyyy",Date())-1),1,0))=0,Null,Sum(IIf(DatePart("m",[PaymentDate])>=3 And DatePart("m",[PaymentDate])<=4,1,0))) AS Apr,
IIf(Sum(IIf(DatePart("m",[paymentdate])>=3 And 4 And DatePart("m",[paymentdate])<=5,1,0))=0,Null,Sum(IIf(DatePart("m",[paymentdate])>=3 And 4 And DatePart("m",[paymentdate])<=5,1,0))) AS May,
IIf(Sum(IIf(DatePart("m",[paymentdate])>=3 And 4 And DatePart("m",[paymentdate])<=6,1,0))=0,Null,Sum(IIf(DatePart("m",[paymentdate])>=3 And 4 And DatePart("m",[paymentdate])<=6,1,0))) AS Jun,
IIf(Sum(IIf(DatePart("m",[PaymentDate])>=3 And 4 And DatePart("m",[PaymentDate])<=7,1,0))=0,Null,Sum(IIf(DatePart("m",[PaymentDate])>=3 And 4 And DatePart("m",[PaymentDate])<=7,1,0))) AS Jul,
IIf(Sum(IIf(DatePart("m",[PaymentDate])>=3 And 4 And DatePart("m",[PaymentDate])<=8,1,0))=0,Null,Sum(IIf(DatePart("m",[PaymentDate])>=3 And 4 And DatePart("m",[PaymentDate])<=8,1,0))) AS Aug,
IIf(Sum(IIf(DatePart("m",[PaymentDate])>=3 And 4 And DatePart("m",[PaymentDate])<=9,1,0))=0,Null,Sum(IIf(DatePart("m",[PaymentDate])>=3 And 4 And DatePart("m",[PaymentDate])<=9,1,0))) AS Sep,
IIf(Sum(IIf(DatePart("m",[PaymentDate])>=3 And 4 And DatePart("m",[PaymentDate])<=10,1,0))=0,Null,Sum(IIf(DatePart("m",[PaymentDate])>=3 And 4 And DatePart("m",[PaymentDate])<=10,1,0))) AS Oct,
IIf(Sum(IIf(DatePart("m",[PaymentDate])>=3 And 4 And DatePart("m",[PaymentDate])<=11,1,0))=0,Null,Sum(IIf(DatePart("m",[PaymentDate])>=3 And 4 And DatePart("m",[PaymentDate])<=11,1,0))) AS Nov,
IIf(Sum(IIf(DatePart("m",[PaymentDate])>=3 And 4,1,0))=0,Null,Sum(IIf(DatePart("m",[PaymentDate])>=3 And 4,1,0))) AS Dec,
IIf(Sum(IIf(DatePart("m",[PaymentDate])>=3 And 4 Or DatePart("m",[PaymentDate])<=1,1,0))=0,Null,Sum(IIf(DatePart("m",[PaymentDate])>=3 And 4 Or DatePart("m",[PaymentDate])<=1,1,0))) AS Jan,
IIf(Sum(IIf(DatePart("m",[PaymentDate])=2,1,0))=0,Null,Sum(IIf(DatePart("m",[PaymentDate])>=3 And 4 Or DatePart("m",[PaymentDate])<=2,1,0))) AS Feb,
IIf(Sum(IIf(DatePart("m",[PaymentDate])=3 And DatePart("yyyy",[paymentdate])=DatePart("yyyy",Date()),1,0))=0,Null,Sum(IIf(DatePart("m",[PaymentDate])>=3 And 4 Or DatePart("m",[PaymentDate])<=3,1,0))) AS Mar
And although my paymentdate range is correct the monthly buckets / columns is not.
not sure how to change it so they are also correct?