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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

If AND then else?

Status
Not open for further replies.

supportsvc

Technical User
Jan 24, 2018
249
US
Hello,
I can't seem to get this right.

Code:
If {PR_EmployeeTaxHistory.CalendarMonth} = "01" and ToNumber({PR_EmployeeTaxHistory.CalendarYear}) = Year(CurrentDate()) then ToNumber({PR_EmployeeTaxHistory.CalendarYear}) = Year(CurrentDate())-1 else
ToNumber({PR_EmployeeTaxHistory.CalendarYear}) = Year(CurrentDate())

What is the proper syntax?

I'm trying to have it return last year's data IF it's the current month (January) and current year only.

This is to run 4th quarter data after the end of the year.
So today is a new year and needs to be still producing last year's data then in Feb it'll show the current year's data, etc ....
 
I think something like this should get you just the year or the year-1 which you could then use in selection criteria.
I would use variables, but depending on your case use they might not be necessary.

{@YearChange}
whileprintingrecords;
numbervar qtrsel;

If {PR_EmployeeTaxHistory.CalendarMonth} = "01" and ToNumber({PR_EmployeeTaxHistory.CalendarYear}) = Year(CurrentDate()) then
qtrsel := Year(CurrentDate())-1
else qtrsel := Year(CurrentDate())

 
Not sure how to apply your suggestion with the

{@YearChange}
whileprintingrecords;
numbervar qtrsel;

This is currently the entire Report select formulas

Code:
If ({PR_EmployeeTaxHistory.CalendarMonth} = "01" and ToNumber({PR_EmployeeTaxHistory.CalendarYear}) = Year(CurrentDate())) then (ToNumber({PR_EmployeeTaxHistory.CalendarYear}) = Year(CurrentDate())-1) else
ToNumber({PR_EmployeeTaxHistory.CalendarYear}) = Year(CurrentDate()) and
{PR_EmployeeTaxHistory.TaxGroup} = {?Tax Group}

With this I get last year's data but do not want anyone to have to go in and remove it come February
Code:
ToNumber({PR_EmployeeTaxHistory.CalendarYear}) = Year(CurrentDate())[highlight #FCE94F]-1[/highlight] and
{PR_EmployeeTaxHistory.TaxGroup} = {?Tax Group}
 

You should not have to make any changes come February.
The month will not be 01 so the year will be year of the current date.
It looks like the Report select formula you already have should almost work without any need for my previous post.


If
({PR_EmployeeTaxHistory.CalendarMonth} = "01" and ToNumber({PR_EmployeeTaxHistory.CalendarYear}) = Year(CurrentDate()))
then
(ToNumber({PR_EmployeeTaxHistory.CalendarYear}) = Year(CurrentDate())-1
and
{PR_EmployeeTaxHistory.TaxGroup} = {?Tax Group})
else
(ToNumber({PR_EmployeeTaxHistory.CalendarYear}) = Year(CurrentDate())
and
{PR_EmployeeTaxHistory.TaxGroup} = {?Tax Group})

 
It still comes up blank
only time it produces the data for last year is by this

ToNumber({PR_EmployeeTaxHistory.CalendarYear}) = Year(CurrentDate())[highlight #FCE94F]-1[/highlight] and
{PR_EmployeeTaxHistory.TaxGroup} = {?Tax Group}
 
Tried this as well, doesn't work either :(

Code:
If 
(Month(CurrentDate)= 1 and ToNumber({PR_EmployeeTaxHistory.CalendarYear}) = Year(CurrentDate()))
then 
(ToNumber({PR_EmployeeTaxHistory.CalendarYear}) = Year(CurrentDate())-1
and
{PR_EmployeeTaxHistory.TaxGroup} = {?Tax Group})
else
(ToNumber({PR_EmployeeTaxHistory.CalendarYear}) = Year(CurrentDate()) 
and
{PR_EmployeeTaxHistory.TaxGroup} = {?Tax Group})
 
Got this from DBlank and seems to be working now

Code:
( 
(MONTH(today)=1 and 
ToNumber({PR_EmployeeTaxHistory.CalendarYear}) = Year(today)-1) 
OR 
((MONTH(today)>1 and ToNumber({PR_EmployeeTaxHistory.CalendarYear}) = Year(today)) 
) 
and 
{PR_EmployeeTaxHistory.TaxGroup} = {?Tax Group})
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top