Print Page | Close Window

If AND then Else?

Printed From: Crystal Reports Book
Category: Crystal Reports 9 through 2020
Forum Name: Technical Questions
Forum Discription: Formulas, charting data, Crystal syntax, etc.
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=22713
Printed Date: 30 Apr 2024 at 12:40pm


Topic: If AND then Else?
Posted By: techsupport
Subject: If AND then Else?
Date Posted: 02 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 ....


-------------
____________________
Thank you very much!



Replies:
Posted By: DBlank
Date Posted: 03 Jan 2019 at 6:04am
what is your current select statement


Posted By: techsupport
Date Posted: 03 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

-------------
____________________
Thank you very much!


Posted By: DBlank
Date Posted: 03 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
Date Posted: 03 Jan 2019 at 10:07am
Doesn't work :(

-------------
____________________
Thank you very much!


Posted By: techsupport
Date Posted: 03 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})


-------------
____________________
Thank you very much!


Posted By: DBlank
Date Posted: 04 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
Date Posted: 04 Jan 2019 at 12:48pm
Thank you

Interesting

however it's still not working :(

-------------
____________________
Thank you very much!


Posted By: DBlank
Date Posted: 07 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})


Posted By: techsupport
Date Posted: 07 Jan 2019 at 7:29am
oh geez
i didn't notice that

it seems to be working now

thank you!

-------------
____________________
Thank you very much!



Print Page | Close Window