Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: If AND then Else? Post Reply Post New Topic
Author Message
techsupport
Groupie
Groupie


Joined: 03 Jun 2014
Location: United States
Online Status: Offline
Posts: 41
Quote techsupport Replybullet Topic: If AND then Else?
    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 ....


Edited by techsupport - 02 Jan 2019 at 9:40am
____________________
Thank you very much!
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet Posted: 03 Jan 2019 at 6:04am
what is your current select statement
IP IP Logged
techsupport
Groupie
Groupie


Joined: 03 Jun 2014
Location: United States
Online Status: Offline
Posts: 41
Quote techsupport Replybullet 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!
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet 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))
IP IP Logged
techsupport
Groupie
Groupie


Joined: 03 Jun 2014
Location: United States
Online Status: Offline
Posts: 41
Quote techsupport Replybullet Posted: 03 Jan 2019 at 10:07am
Doesn't work :(
____________________
Thank you very much!
IP IP Logged
techsupport
Groupie
Groupie


Joined: 03 Jun 2014
Location: United States
Online Status: Offline
Posts: 41
Quote techsupport Replybullet 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!
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet 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})
IP IP Logged
techsupport
Groupie
Groupie


Joined: 03 Jun 2014
Location: United States
Online Status: Offline
Posts: 41
Quote techsupport Replybullet Posted: 04 Jan 2019 at 12:48pm
Thank you

Interesting

however it's still not working :(
____________________
Thank you very much!
IP IP Logged
DBlank
Moderator
Moderator


Joined: 19 Dec 2008
Online Status: Offline
Posts: 9053
Quote DBlank Replybullet 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})

Edited by DBlank - 07 Jan 2019 at 2:24am
IP IP Logged
techsupport
Groupie
Groupie


Joined: 03 Jun 2014
Location: United States
Online Status: Offline
Posts: 41
Quote techsupport Replybullet 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!
IP IP Logged
Post Reply Post New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum



This page was generated in 0.033 seconds.