If AND then Else?
Printed From: Crystal Reports Book — Forum Name: Technical Questions
Posted By: techsupport — 2 Jan 2019 at 8:53am
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
Posted By: DBlank — 3 Jan 2019 at 6:04am
what is your current select statement
Posted By: techsupport — 3 Jan 2019 at 7:19am
?
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
Posted By: DBlank — 3 Jan 2019 at 7:30am
(MONTH(today)=1 and
ToNumber({PR_EmployeeTaxHistory.CalendarYear}) = Year(today-1))
OR
(MONTH(today)>1 and ToNumber({PR_EmployeeTaxHistory.CalendarYear}) = Year(today))
Posted By: techsupport — 3 Jan 2019 at 10:07am
Doesn't work :(
Posted By: techsupport — 3 Jan 2019 at 10:37am
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})
Posted By: DBlank — 4 Jan 2019 at 4:05am
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})
Posted By: techsupport — 4 Jan 2019 at 12:48pm
Thank you
Interesting
however it's still not working :(
Posted By: DBlank — 7 Jan 2019 at 2:23am
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
Posted By: techsupport — 7 Jan 2019 at 7:29am
oh geez
i didn't notice that
it seems to be working now
thank you!
|