If AND then Else?

Printed From: Crystal Reports Book — Forum Name: Technical Questions

Hello,
I can't seem to get this right.


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 ....


Edited by techsupport - 02 Jan 2019 at 9:40am
what is your current select statement
?
This code is in the Report Select section


ToNumber({PR_EmployeeTaxHistory.CalendarYear}) = Year(CurrentDate())


I added ToNumber({PR_EmployeeTaxHistory.CalendarYear}) = Year(CurrentDate())-1 to run the reports for 4th quarter last year but want to set it so no one has to go into and edit it each year
(MONTH(today)=1 and
ToNumber({PR_EmployeeTaxHistory.CalendarYear}) = Year(today-1))
OR
(MONTH(today)>1 and ToNumber({PR_EmployeeTaxHistory.CalendarYear}) = Year(today))
Doesn't work :(
Tried this as well


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})
in a select you do not need the if-then
(
(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})
Thank you

Interesting

however it's still not working :(
Sorry, move the "-1" in the first part to outside the first parenth.
It was giving you the year from yesterday ("year(today-1)") but you want the year from today -1 ("year(today)-1".

(
(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})

Edited by DBlank - 07 Jan 2019 at 2:24am
oh geez
i didn't notice that

it seems to be working now

thank you!