3 weeks ago
Crystal Report Version : 2010
I already have the SQL Select statement to get the data, now, in order to filter the data using two Dates as a Date range, I need to create the Starting Date and End Date, I started doing that. Then, I tried to use those two parameters in the COMMAND file I created, but is not working, it means all the data is passing. thru.
Those two parameters, I need to use as the End Date : the Current Date, I created as p_CurrentDate.
And for the Beginning Date, I need to use a calculated value as : The first Parameter minus 30 days, it means : f_CurrentDate - 30 Days.
These should be taken by default, to be run by SAP BI and creating an excel file.
Then.
First Paremeter : p_CurrentDate : Taking the CurrentDate from the System
Second Parameter : p_CurrentDate - 30 Days.Date,
But, the user, also, could run the Crystal report to get a different period of time, it means the CurrentDate would be different, because it becomes the end date, then, the Begin Date sould be equeally 30 days before.
So, the first parameter ( p_CurrentDate ), should be flexible to get the really Current Date or to use a different date to caluclate the second parameter, maybe using a formula.
So, for some reason, when I run the report, is not taking the two parameters to filter the data and show only the records in that Date range.
May I missing something in the parameters Settings?
I attached a file with the setup of that Parameter, the second one is very similar.
Request clarification before answering.
Create a new formula and write something like that :
local datevar firstday;
local datevar lastday;
firstday:={?p_date1}; lastday:={?p_date2};
// Auto mode -> Show : last month
if firstday<date(1900,1,1) then
cstr(date(DateAdd ('m', -1, cdate(year({?p_date2}),month({?p_date2}),1))),'MMMM yy')
// Else -> Show 2 dates
else
cstr(firstday)+' to '+cstr(lastday);
Then, put you formula on header.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi SDE-K, I was very happy with the solution you gave me, in fact was ready to prepare the change and pass it to Production, when the Requester contacted me to add a new requirement to the same report, now they want to have the same option to filter the plant #, adding a new parameter, to have the option by default "All" plants or a specific plant from a list created in the parameter, then I figured out that I least I needed to add some lines : local stringvar plantno;, then assign the received value in the parameter "p_plantno", the issue I have is how to set the If then else to cover two options "All" plants or just one selected by the user, let me know if that's possible. Thanks.
This what I did for the formula checking the dates.
I believe is possible to have the same formula and using it to include a third parameter, the plantno to use "All" or one specific plant from a list of possible plants : '02-07-12-14-18-19-22-26-27-67', and if you remember you gave me also the option to have a header with the Month & Year, or a Period of time, then, because I am adding a third parameter, I believe I need another formula to print then the Plant : All Plants or the Specific plant.
Do you think that is feasible?
This is the Formula I have for the heading, that also you recommended to me, part of the text is in french.
Thanks in advance.
Hello,
Did you filter the query with your parameter?
You should have something like this :
Best.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I think you only need one parameter for the “reference date”. Since the other date is 30 days before, you need to take the reference date - 30.
I don't know if SAP BI can send an empty date.
To control the value of the date parameter, you can work with a formula in "field explorer"
or directly in the record selection filter.
If SAP feeds the "empty" date with a distant date, you can do:
if {?p_currentdate}<date(1900,1,1) then
{command.dat}>=currentdate-30 and {command.dat}<=currentdate
else
{command.dat}>={?p_currentdate}-30 and {command.dat}<={?p_currentdate}
If you create a formula field, you will must call it to filter records :
OK, I'm not sur to understand your second option.
Option 1 : You want the records for the last month. -> Today = May 1st, 2025 to May 31, 2025.
Option 2 : You want the records for the user parameters.
If it's that, I will use 3 parameters : start date, end date and mode to use (=option #1 or #2).
For exemple :
Auto mode is the last month.
+ 2 dates parameters
Create formula field :
With
local datevar firstday;
local datevar lastday;
// Initiate with parameter
firstday:={?p_date1}; lastday:={?p_date2};
// If the automode, first date is the first days of current month – 1 month. Last days is the first days of current month – 1 day.
if {?p_automode} then (
firstday:=date(DateAdd ('m', -1, cdate(year(currentdate),month(currentdate),1)));
lastday :=date(DateAdd ('d', -1, cdate(year(currentdate),month(currentdate),1)))
);
// Then, I filter records :
{Command.dat}>=firstday and {Command.dat}<=lastday;
You put the formula in records select.
If you don’t want the p_automode parameter, you must check the dates parameters. Imagine date #1 is not use = initiate with old date. Date #2 is your reference date (= first date of month)
local datevar firstday;
local datevar lastday;
firstday:={?p_date1}; lastday:={?p_date2};
if firstday<date(1900,1,1) then (
firstday:=date(DateAdd ('m', -1, cdate(year({?p_date2}),month({?p_date2}),1)));
lastday :=date(DateAdd ('d', -1, cdate(year({?p_date2}),month({?p_date2}),1)))
);
{Command.dat}>=firstday and {Command.dat}<=lastday;
User | Count |
---|---|
40 | |
15 | |
10 | |
9 | |
5 | |
5 | |
5 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.