Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multiple If statements in one formula - not possible? 1

Status
Not open for further replies.
Feb 23, 2006
8
US
I have the following series of IF statements in one formula, but when I try to save it's telling me that "The remaining text does not appear to be a part of the formula", and selects everything after the first If...Else statement.

I would think this could be avoided with the EndIf command, but that doesn't appear to be working either. When I leave just the first IF statement there, it runs correctly, but when I try to add the EndIf it highlights the EndIf and gives me that same message.

HELP!!

If DayOfWeek (CurrentDate) = 1 or DayOfWeek (CurrentDate) = 7 Then
+ 0
Else
+ 1

If DayOfWeek (CurrentDate - 1) = 1 or DayOfWeek (CurrentDate - 1) = 7 Then
+ 0
Else
+ 1

If DayOfWeek (CurrentDate - 2) = 1 or DayOfWeek (CurrentDate - 2) = 7 Then
+ 0
Else
+ 1

If DayOfWeek (CurrentDate - 3) = 1 or DayOfWeek (CurrentDate - 3) = 7 Then
+ 0
Else
+ 1

If DayOfWeek (CurrentDate - 4) = 1 or DayOfWeek (CurrentDate - 5) = 7 Then
+ 0
Else
+ 1

If DayOfWeek (CurrentDate - 5) = 1 or DayOfWeek (CurrentDate - 5) = 7 Then
+ 0
Else
+ 1

If DayOfWeek (CurrentDate - 6) = 1 or DayOfWeek (CurrentDate - 6) = 7 Then
+ 0
Else
+ 1

If DayOfWeek (CurrentDate - 7) = 1 or DayOfWeek (CurrentDate - 7) = 7 Then
+ 0
Else
+ 1

If DayOfWeek (CurrentDate - 8) = 1 or DayOfWeek (CurrentDate - 8) = 7 Then
+ 0
Else
+ 1
 
A formula can only return a single value and your formula would return 9 separate values (0/1). If your goal is to return the SUM of the 9 values you should put parens around each statement and put plus signs between them to add them all together.

Ken Hamady, On-site Custom Crystal Reports Training & Consulting
Public classes and individual training.
Guides for Formulas, Parameters, Subreports, VB, .NET, Tips and Tricks
 
What are you trying to do? The formula (if it were corrected to work) basically says that if any day within the last 8 days is a Saturday or Sunday then 0 else 1--which means the result would always be 0.
You should not use plus signs unless you adding numbers or concatenating a string. If you are trying to return the date that is the beginning of the week (Sunday), then you would just use:

currentdate - dayofweek(currentdate) + 1

-LB
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top