SSRS Report Date Parameter Default for the current Year - date

I have an SSRS Report I've created with a "Date/Time" Parameter I have created. I am trying to create a Parameter that Defaults to the Current Year. For example in "2020" I want the Paramater to default to "01/01/2020" when we hit 2021 I want it to default to "01/01/2021" Here is what I have tried. For my default value in the parameter I have the following expression with no success.
=CDate(Year(Now())+"-"+Month(01)+"-"+Day(01))

You can do this using the following expression.
=DateSerial(YEAR(Today()), 1, 1)
You can use CDate but that relies on strings. DateSerial is easier to work with in your scenario.

Related

How could i set yesterday value as default value for a numeric parameter in datastage?

I have a numeric datatype parameter in Datastage.
*parameter name: VAR_ETL_DATE
*format:YYYYMMDD
*ex:20210612
How could i set yesterday value as default value for this parameter?
Format:YYYYMMDD (numeric)
*Example: Today:20210824
*When i run a job including VAR_ETL_PARAMETER with default value, The job should run with yesterday value(20210823)
You can't set it in a static sense, because the date of yesterday is a moving target. The best you could do would be to set it in a controlling sequence job that invokes your job.
Use any of the date offset functions to set the value. For example you could use Date() - 1 as the generating expression directly in the Job activity in your sequence.

SSRS : Argument 'VarExpr' is not a valid value

I am trying to calculate Month Name based on the Datepart calculation in SSRS.This code is working but with a warning..
=Switch(DATEPART(DateInterval.Month,Fields!TRANSACTION_DATE.Value)=12,"December",
DATEPART(DateInterval.Month,Fields!TRANSACTION_DATE.Value)=11,"November",
DATEPART(DateInterval.Month,Fields!TRANSACTION_DATE.Value)=10,"October",
DATEPART(DateInterval.Month,Fields!TRANSACTION_DATE.Value)=9,"September",
DATEPART(DateInterval.Month,Fields!TRANSACTION_DATE.Value)=8,"August",
DATEPART(DateInterval.Month,Fields!TRANSACTION_DATE.Value)=7,"July",
DATEPART(DateInterval.Month,Fields!TRANSACTION_DATE.Value)=6,"June",
DATEPART(DateInterval.Month,Fields!TRANSACTION_DATE.Value)=5,"May",
DATEPART(DateInterval.Month,Fields!TRANSACTION_DATE.Value)=4,"April",
DATEPART(DateInterval.Month,Fields!TRANSACTION_DATE.Value)=3,"March",
DATEPART(DateInterval.Month,Fields!TRANSACTION_DATE.Value)=2,"February",
DATEPART(DateInterval.Month,Fields!TRANSACTION_DATE.Value)=1,"January")
Warning :
[rsRuntimeErrorInExpression] The Value expression for the field ‘MONTH_NAME’ contains an error: Argument 'VarExpr' is not a valid value.
Please suggest how to remove this error.
Based on your expression, you should be able to use a much simpler expression with different date functions:
=MonthName(Month(Fields!TRANSACTION_DATE.Value))

Convertion parameter numeric month to title month

I have month parameter in JasperReports report which will be changed into title of month. I didn't use any query to change them. I try this code:
$P{MONTH}.intValue()==1?"JAN":
$P{MONTH}.intValue()==2?"FEB":
$P{MONTH}.intValue()==3?"MAR":
$P{MONTH}.intValue()==4?"APR":
$P{MONTH}.intValue()==5?"MAY":
$P{MONTH}.intValue()==6?"JUN":
$P{MONTH}.intValue()==7?"JUL":
$P{MONTH}.intValue()==8?"AUG":
$P{MONTH}.intValue()==9?"SEP":
$P{MONTH}.intValue()==10?"OCT":
$P{MONTH}.intValue()==11?"NOV":"DEC";
but it didn't work. Could anyone know the solution for me?
This is what I use
$F{MONTH}.intValue()==1?"JAN":
$F{MONTH}.intValue()==2?"FEB":
$F{MONTH}.intValue()==3?"MAR":
$F{MONTH}.intValue()==4?"APR":
$F{MONTH}.intValue()==5?"MAY":
$F{MONTH}.intValue()==6?"JUN":
$F{MONTH}.intValue()==7?"JUL":
$F{MONTH}.intValue()==8?"AUG":
$F{MONTH}.intValue()==9?"SEP":
$F{MONTH}.intValue()==10?"OCT":
$F{MONTH}.intValue()==11?"NOV":"DEC"
It may be the semi-colon at the end that's the problem
It may also be that you are using a Parameter - .intValue() doesn't seem valid for a Parameter

Sending parameters to report from Java code

I need to send a timestamp value as parameter from java to JR report. I tried the following code but I'm getting a blank report.
My JRXML File:
`
`
The report works fine with normal date parameter but fails to display with Time-stamp value.
My Java code :
`
I tried various values of timestamp Ex: (new java.sql.Timestamp(2013-02-27) but it is not working.
Use:
new SimpleDateFormat("yyyy-MM-dd").parse("2012-01-01");
Simply putting:
new Date(2012-01-01);
would give definitely wrong date, probably EPOCH start date.
Ensure it's MM not mm when parsing your date for month. See SimpleDateFormat javadoc
EDIT
See the image. The date your default values will generate is around 1970.
Hence your Between Condition will get all the values between 1970 to Today.
EDIT : 2
In my opinion You are setting wrong parameter in Table's datasource.
Instead of setting From_Date & To_Date from Fields set them as parameter from the main report itself.
Refer Image.

jasperreport server scheduling with today's date

I'm trying to set up a report using the scheduler with today's date as the input parameter. Is this possible?
I see you can set static value for the input parameter but cannot set it to now() or some variant.
report parameter name is $P{Date}
I've set the default expression to
($P{Date} == null ? new Date() : $P{Date})
And it seems to work.
Sam, in your report, could you create a parameter with a default value of today's date (see Filtering on a Date Range: http://jasperforge.org/plugins/mwiki/index.php/Jasperserver/Filtering_on_a_date_range)? Then make it mandatory so JasperReports Server will choose the default value if no other input is given.