Has value function crystal reports - crystal-reports

In my report I have 3 parameters when, week and year.
If I select When=schedule then the report should run for current week without considering year and week values given in parameter window.
If I select when=Now then the report should run for week value and month value that we have given in parameter window.
Please suggest.
I tried like this but not working.
if hasvalue({?Week}) and HasValue({?Year}) and {?When} = 'Now'
Then
{?Week} = {Command.WEEK} and {?Year} = {Command.YEAR}
else
({?Week} = DatePart ("ww", Currentdatetime) and {?Year} = DatePart ("yyyy", Currentdatetime)

In crystal report ISNULL and INSTR function will use in this condition.
ISNULL:- check the value is null, then return true else false.
INSTR :- check the substring in string, if found then give index else 0 return.
Check detail in links
http://publib.boulder.ibm.com/infocenter/rsahelp/v7r0m0/index.jsp?topic=/com.businessobjects.integration.eclipse.designer.doc/designer/Crystal_Syntax47.html
In your case
if isnull({?Week}) and isnull({?Year}) and isnull{?When}
Then
return false
else
//in else again check with if else condition
if {?When} = 'schedule'
then
do something
else
do something

My approach would be:
Instead of checking for null values for the parameters.. Give a default value for the parameter and check that value for the false condition.
Suppose let us take default value as None
if {?Week}="None" and {?Year}="None" and {?When} = 'Now'
Then
{?Week} = {Command.WEEK} and {?Year} = {Command.YEAR}
else
({?Week} = DatePart ("ww", Currentdatetime) and {?Year} = DatePart ("yyyy", Currentdatetime)
Note: Above code is just an example change it as per your requirement.

You can use by this way:
if {?Week}<>"" then {Command.WEEK}={?Week} else {Command.WEEK}={Command.WEEK}
Hope this will help.

Related

Dynamic Measure From Date Slicer Not working as expected

I have similar problem statement of (PowerBI/DAX: Unable to correctly compare two dates)
where I'm selected the start date and end date from slicer and wrote DAX for the measures as
Start_Date = CALCULATE(Min('Calendar'[Date]),ALLSELECTED('Calendar'))
End_Date = CALCULATE(Max('Calendar'[Date]),ALLSELECTED('Calendar'))
And I use them to compare with a column and return TRUE or FALSE.
IsTrue_Flag = IF(table[prod_date]>=[Start_Date] && table[prod_date] <= [End_Date], TRUE, FALSE)
But all my values are turning as TRUE which is not the case.
Where did I go wrong with the DAX? please help

Tableau Calculated Field of Running Average for the last month

Hey Guys I am trying to do a calculation for a Running Average over the last month in a calculated field in Tableau. However I struggle with defining the last month range and adding it to the calculation. I thought of using
IF [date] >= DATEADD('month', -1, TODAY()) THEN
RUNNING_AVG(SUM( IF [Entry Type] = 'Sale'
THEN [Invoiced Quantity]
ELSE 0
END )) END
However this is not working at all. I hope someone can help me out. Cheers
This worked out:
(SUM( IF [Entry Type] = 'Sale' AND [Posting Date] >= DATEADD('month',-1,TODAY())
THEN [Invoiced Quantity]
ELSE 0
END
))
You do not have to write this into calculated field. Just filter date column and set that to be always filter for last 30 days, or last month. Then, use "calculated field" section just for calculation independently from the "date" which is already considered in filter section.
Good luck

postgresql query year (integer) field equals year of current date

This seems like it should be fairly simple and straight forward but I haven't yet found the right combination. I have a column called last_assess_yr that is an integer. I am trying to find all rows from my_table where '01-01' + 'year' < current_date and give them a value in a new column. I have the following:
SELECT last_assess_yr,
CASE
WHEN format('01-01-%s'::text, last_assess_yr)::timestamp without time
zone < current_date
THEN YES
ELSE NO
END AS assess_value
FROM my__table
but, the results are not correct
You don't actually need to convert the integer into a timestamp, you could just compare the extracted year to the integer.
select
case when last_assess_yr < extract('year' from current_date)::int
then 'YES' else 'NO'
end
However for reference the following will work:
select
case when format('01-01-%s'::text, 2017)::timestamp < current_date
then 'YES' else 'NO'
end
i.e. you do not need to remove time (of day) when you convert a string of '01-01-2017' to a timestamp.
and: I assume YES and NO also need to be treated as literals: 'YES' and 'NO'
In case someone else is looking, this worked for me:
WHEN last_assess_yr > 0 AND format('%s-05-05'::text, w.last_assess_yr)::timestamp <
current_date THEN 'yes'
ELSE 'no'
END

Crystal date based record selection; no lower date through Saturday

I want to set up a Crystal report with a default date range for record selection. I want the date range to be no lower date through Saturday of the current week based on the formula field {#Calc Promise Date}. I am a lighter end user of Crystal and am having trouble with this.
I can use:
{#Calc Promise Date} in AllDatesToToday
But I am looking for a way to have the results be all dates to Saturday of the current week.
Thanks in advance for your help.
Thanks to help from Siva on a similar question, I now have the answer for this one.
Make a new Formula Field of "End Date" that contains:
if DayOfWeek (DateSerial(Year(currentdate),Month(currentdate),Day(currentdate))) = 1
then DateSerial(Year(currentdate),Month(currentdate),Day(currentdate)+6)
else if DayOfWeek(DateSerial(Year(currentdate),Month(currentdate),Day(currentdate))) = 2
then DateSerial(Year(currentdate),Month(currentdate),Day(currentdate)+5)
else if DayOfWeek(DateSerial(Year(currentdate),Month(currentdate),Day(currentdate))) = 3
then DateSerial(Year(currentdate),Month(currentdate),Day(currentdate)+4)
else if DayOfWeek(DateSerial(Year(currentdate),Month(currentdate),Day(currentdate))) = 4
then DateSerial(Year(currentdate),Month(currentdate),Day(currentdate)+3)
else if DayOfWeek(DateSerial(Year(currentdate),Month(currentdate),Day(currentdate))) = 5
then DateSerial(Year(currentdate),Month(currentdate),Day(currentdate)+2)
else if DayOfWeek(DateSerial(Year(currentdate),Month(currentdate),Day(currentdate))) = 6
then DateSerial(Year(currentdate),Month(currentdate),Day(currentdate)+1)
else if DayOfWeek(DateSerial(Year(currentdate),Month(currentdate),Day(currentdate))) = 7
then DateSerial(Year(currentdate),Month(currentdate),Day(currentdate)+0)
Then in Record Selection reference that formula. In my case, the correlating date range for the records was a Through Current Date Range formula field, so my Record Selection was then updated to include the following line:
{#Through Current Date Range}<{#End Date}

Unable to convert from Julian INT date to regular TSQL Datetime

Help me Stackoverflow, I'm close to going all "HULK SMASH" on my keyboard over this issue. I have researched carefully but I'm obviously not getting something right.
I am working with a Julian dates referenced from a proprietary tool (Platinum SQL?), though I'm working in SQL 2005. I can convert their "special" version of Julian into datetime when I run a select statement. Unfortunately it will not insert into a datetime column, I get the following error when I try:
The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.
So I can't setup datetime criteria for running a report off of the Stored Procedure.
Original Value: 733416
Equivalent Calendar Value: 01-09-2009
Below is my code... I'm so close but I can't quite see what's wrong, I need my convert statement to actually convert the Julian value (733416) into a compatible TSQL DATETIME value.
SELECT
org_id,
CASE WHEN date_applied = 0 THEN '00-00-00'
ELSE convert(char(50),dateadd(day,date_applied-729960,convert(datetime, '07-25-99')),101)
END AS date_applied,
CASE WHEN date_posted = 0 THEN '00-00-00'
ELSE convert(char(50),dateadd(day,date_posted-729960,convert(datetime, '07-25-99')),101)
END AS date_posted
from general_vw
SELECT
org_id,
CASE WHEN date_applied = 0 OR date_applied < 639906 THEN convert(datetime, '1753-01-01')
ELSE dateadd(day,date_applied-729960,convert(datetime, '07-25-99'))
END AS date_applied,
CASE WHEN date_posted = 0 OR date_applied < 639906 THEN convert(datetime, '1753-01-01')
ELSE dateadd(day,date_posted-729960,convert(datetime, '07-25-99'))
END AS date_posted
from general_vw
You're casting to char but want a datetime so that's one easy fix.
You were also using '00-00-00' as your minimum date, but the minimum TSQL date is '1753-01-01'. Alternatively you could use something like ('1900-01-01') but that would need a change to the "less than" date_applied comparer.
I've added a "less than" date_applied comparer too. I calculated this as "SELECT 729960 + datediff(day,convert(datetime, '07-25-99'), convert(datetime,'1753-01-01'))". Any number less than this would cause a date underflow.