I have been working on getting a report out for long without success.
I have a report that select based on parameter fields of date and boolean. Currently I have to create 3 reports. One based on dates, one based on the boolean and one based on both.
However, I want my report to be able to select all dates if the user does not input date in the parameter or select all booleans if user does not select one.
Currently I used this
if ({?Start Date} = DateTimeValue('') or {?End Date} =DateTimeValue('')) then
{rectReport.Call date} in DateTimeValue ('1753-01-01 00:00:00') to CurrentDateTime
else
({rectReport.Call date} in {?Start Date} to {?End Date}) and {rectReport.EngineDown} = {?Engine Down}
The basic Idea I am looking for is that the user can decide to select only one parameter instead of the two.
Any help will be highly appreciated.
Thanks,
Bimbo
In Crystal 2008 you have the option of making parameters optional. What you could do is create one report with both parameters and then set both parameters as optional. In your record selection formula you could do something like this:
(if (HasValue({?Startdate}) and HasValue({?Enddate}))
then {table.datefield} in {?Startdate} to {?Enddate}
else {table.datefield} in {defaultstartdate} to {defaultenddate})
and (if HasValue({?BoolParam}) then {table.boolfield} = {?BoolParam}
else {table.boolfield} = {defaultbool})
If you wanted to select ALL tables if the user did not input the parameter, you could just omit the else-statements.
(note: Sorry if that syntax isn't correct (I am just getting back into CR again), but you get the idea.)
EDIT: Since optional parameters aren't available in CR10, couldn't you just use parameter default values for the dates instead? For the boolean, you could just make a parameter with 3 values: true, false, and "all" and then default to the "all" value when running the report.
I don't know your particular situation, but the way we handle this (specifically for Defined Periods vs User-specified-Date-Range) is through being able to set defaults.
Our main environment is BOE XI.
Our parameters might be
ReportPeriod (String Variable)
and
CustomDates (DateTime Range, but will work as two discrete dates)
Example params for ReportPeriod might be
1 Day
7 Days
Last Month
Custom Dates
Formulas are used to calculate date limits that will be used in the record selection. I start with the END DATE, as it is convenient for our period reports.
#EndDate
Select ?ReportPeriod
Case
"1 Day", "7 Days" : CurrentDate
// Conveniently defaults to MIDNIGHT
"Last Month" : Maximum(LastFullMonth)
"CustomDates" : Maximum(?CustomDates)
// Or discrete parameter for end date
default : CurrentDate
#BeginDate
Select ?ReportPeriod
Case
"1 Day" : DateAdd("d", -1, #EndDate)
"7 Days" : DateAdd("d", -7, #EndDate)
"Last Month" : Minimum(LastFullMonth)
"CustomDates" : Minimum(?CustomDates)
// Or discrete parameter for end date
default : DateAdd("d", -1, #EndDate)
And, let me caution against using CurentDateTime unless necessary. Every time you try to step through the report, the selection will have changed: 5:01:10 PM ... 5:01:16 PM ... 5:01:24 PM ...
When publishing a report, we set default date (it doesn't matter what, it's only used for CUSTOM and the customer resets it then), and a default ReportPeriod.
The report can be scheduled periodically (based on ReportPeriod) and it will always run.
If the user wants to do custom dates (historic reporting, etc.), then they can chose that for report period, and then set whatever start and end dates they need.
Helpful?
Related
I want the Slicer in Power BI to select the most recent date of the selection to be selected automatically.
Here is an example of the drop down:
https://i.imgur.com/IykHSlI.png
This drop down differs from the Client selection.
I solved this issue the following way:
I created one Report with a filter to Default_Date (which opens first)
I used a Calculated Column [Default_Date] to populate the filter (which is hidden)
In my case the user wanted to see Yesterday's data as the default date so I selected 'Yesterday' on my filter.
Then I put a button that opens another duplicated copy of the Report [Hidden Tab] that contains a full calendar filter, so the user can select any other dates he likes, this hidden report has another button that returns the user to the main report [if he wants to].
picture of my filter (which I collapse and hide under a color box/banner)
Here is the formula for the calculated column (used in the filter):
Default_Date =
VAR TodaysDate =
TODAY()
VAR YesterdayDate =
TODAY() - 1
VAR reportDate =
SWITCH(TRUE(),
'Calendar'[Date] = TodaysDate, "Today",
'Calendar'[Date] = YesterdayDate, "Yesterday",
"Before Yesterday"
)
RETURN
reportDate
Use Default_Date in your filter, and you can replace TODAY() with
CALCULATE(Max(Table[Date]),All(Table))
and remove what you don't need.
If you want to get the Last Date of selected items, then
CALCULATE(Max(Table[Date]),ALLSELECTED(Table))
Table may need to be in quotes to work: 'Table'[Date]
I hope this helps.
There isn't to set a default value in Power BI, but there are a few around about ways. First you can try Persistent Filters that can preserve the filters selected. The other option, is to create in your data set, if you have a calendar table, or are able to add it to your column a current date flag, that you can apply as a filter to your report.
For example you can use the TODAY() to return todays date, and check against your date column.
Calculated column = IF(MONTH(TODAY()) = MONTH('table'[DateColumn]) && YEAR(TODAY()) = YEAR('table'[DateColumn]), "Y", "N")
You can run the report and it will always filter on the latest date, however you will have to remove the filter if you want to see other dates. You could set up bookmarks so that you can easily add/remove filter to the report. So you would have one bookmark with latest date, and the other to remove it. You can allow the slicer box to appear when you select the 'remove current month' bookmark
Hope that helps
I have written the following expression,
#for the 1st Column
CASE WHEN month = 'Nov'
THEN AVG(Marks by Student)
END
#for the 2nd Column
CASE WHEN month = 'Dec'
THEN AVG(Marks by Student)
END
I have Month as prompt. So, when I run the report. The data is being displayed only for December. But when I select November in prompt, November data is displayed.
Is there anything am going wrong with the expression?
Wait you are saying that the result is "wrong" because it displays November when you FILTER for November?!
You do know that filters are actually WHERE clauses which cut off the data stream!
I am currently working with reports in Navision by a "book sales" currently use 2 variables "Date" one for the start and one for the end of the filter, but I wonder if you can only use a single variable where the user directly enter "month" and "year". Thank You!
If you are setting the filter with SETRANGE you need two values. But if you use SETFILTER you can use a string with a date filter like this:
010115..103115
p1..p3
and the just:
DateField.SETFILTER(filterstring);
Yes, when the user put the month and year data you by code transform this info in date values example:
Variables from and to = date
from := DMY2DATE(1, Month, Year);
EVALUATE(to, FORMAT(CALCDATE('+1M', Desde) -1));
YourTable.SETRANGE("Posting Date", from, to);
I have a jquery calendar for the start date of a project.
Using Watir (automated browser driver, a gem for ruby), I have a set date that I would like to enter in.
The calendar start date is always today's date, whatever that may be for the day it is used. I was wondering if there was a way that ruby can process what today's date is, and use the specified date provided by the user, to calculate the difference of months between them.
Here is an example of the Calendar plugin: http://jqueryui.com/datepicker/
example:
today's date is 30/10/2012, if there was a project that were to start on the 20/12/2012, that would be 2 months from now, so 2 clicks on the next month button.
Is there a way I could do this?
Here is how I approached a similar situation with JSdatepicker:
$today = Time.now.strftime("%e").gsub(" ", "") #one digit day of month without leading space
#browser.text_field(:id => /dateAvailable/).click
Watir::Wait.until(60) {#browser.div(:id => /dateAvailable_popup_cal/).td(:text => $today).exists?}
#browser.div(:id => /dateAvailable_popup_cal/).td(:text => $today).click
Set or grab the date.
Click the text_field that fires the JSDatePicker object
Wait until the calendar actually pops up
The current month is shown, so choose today's date number.
In your case, you also need to set the month. Whether prompting the user for this, or choosing "today", the theory is the same:
$month = Date::MONTHNAMES[Date.today.month] #etc
Pseudo-code making lots of assumptions (only future dates, month name shown on calendar as text, etc):
while !#jquerytablewindow.text.include?($month)
next_month_button.click
end
I don't see a specific advantage to my method versus counting each month, unless of course we add a month to the calendar one day and you still want your code to work!
You could do:
#End date converted to date object
specified_date = '20/12/2012'
end_date = Date.parse(specified_date)
#Start date (today - 30/10/2012)
today = Date.today
#Determine difference in months
number_of_months_up_to_today = (today.month + today.year * 12)
number_of_months_up_to_end = (end_date.month + end_date.year * 12)
clicks_required = number_of_months_up_to_end - number_of_months_up_to_today
#=> 2
Basically it is counting the number of months since the year 0 and then finding the difference.
I have an object which contains a list of due dates, I am trying to build a system which returns the due date when a specified date is 1 month or less before the due date. It should return the due date in this format "1st Feb 2009". Let me clarify, using my current code
#Build array of estate objects
estate.due_dates = "1st Feb, 3rd May, 1st Aug, 5th Nov"
estate2.due_dates = "28th Feb, 31st May, 31st Aug, 30th Nov"
estates = [estate,estate2]
set_due_date_on_estates("1st Jan 2009",estates) #Run function - should return "1st Feb 2009,28th Feb 2009"
def set_due_date_on_estates(date,estates)
estates.each{|estate|
estate.due_dates.split(",").each{|due_date|
((date)..(date >> 1)).each{|current_date|
estate.set_reminder(due_date + current_date.strftime("%Y")) if current_date.strftime('%d %m') ==
Date.parse(due_date).strftime('%d %m')
}
}
end
}
The issue I am having, is that my list of due dates doesnt have a Year, so I am looping through my range and checking if the dates are equal using the format "%d %m". If so I am setting the reminder in the estate object by using the current "due date" in the loop concatenated with the Year of the "current date" in the loop.
Am not too happy with the code, in particular the nested loops and wondered if there was a better way I could deal with checking that the due_dates where in the date range, even though the due_dates dont have a year. Thanks
You could use date parsers: Kronos, chronic
Example for kronos:
def parse_date(date)
Kronos.parse(date.sub(/\d{4}$/, ''))
end
This function gives you a Kronos object without year which is more easily to compare, build range and so on.
Yes you can use Chronic and also you can write a worker which will keep checking if the specified date is 1 month or less before the due date at regular interval. And ask that worker to do something if result is true (say send you an email or anything if date is within due date) you can find more information about worker by googling Resque and Redis. Another option would be to convert both dates on some base reference and then do the calculations.