Syntax Issues: Sum if in SELECT statement

Hello,

I need to update Code Block 1. to sum the values of Data.WeekValue if the value is greater than 25 and less than 50.

Code Block 1.
Sum(Data.WeekValue) AS WeekValues

Open in new window


I'm having troubles with the syntax, I've tried Code Block 2. but not sure how to:
1.  Assign a field name i.e. the AS WeekGreaterThan25
2.  If value isnt in the range I would like the value to be 0 only if no values are in the defined range (don't want to override the sum if the last value isn't in the range defined).

Code Block 2.
Sum(IIF(([Data].[WeekValue] > 25 AND [Data].[WeekValue] <50 ),  AS WeekGreaterThan25

Open in new window


Thanks
AndyC1000Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

IrogSintaCommented:
Try this:
Sum(IIF([Data].[WeekValue] > 25 AND [Data].[WeekValue] <50, [Data].[WeekValue], 0)  AS WeekGreaterThan25
You can also try:
Sum(IIF([Data].[WeekValue] Between 26 AND 49, [Data].[WeekValue], 0) AS WeekGreaterThan25
0
AndyC1000Author Commented:
When I run the first sum if example there's a syntax error missing operator in expression.
0
IrogSintaCommented:
Sorry about that... both those expressions need an extra closing parenthesis.
Sum(IIF([Data].[WeekValue] > 25 AND [Data].[WeekValue] <50, [Data].[WeekValue], 0))  AS WeekGreaterThan25
Sum(IIF([Data].[WeekValue] Between 26 AND 49, [Data].[WeekValue], 0)) AS WeekGreaterThan25
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Access

From novice to tech pro — start learning today.