SSRS Cascading Params without a dataset - reporting-services

I've done many a cascading param in SSRS but ALL have used datasets, passing in a param value into a query, this time I want to know if a date selection can be done using only expressions.
Periodtype parameter has a value list of 'Day' Or 'Quarter' (those are the labels, the values are "D" and "Q").
I've set the default values of the start and end dates via SSRS expression if periodtype value is "D" then set start and end date to be beginning and end of previous day and if "Q" then similar with previous quarter.
This works when you start up the report, changing the default period type (D or Q).
It won't allow the date to be calculated dynamically when changing the periodtype, can it be done without queries, using just params and expressions, thank-you?

If I've understood your question correctly, I think the issue is not so much to do with datasets, but a long standing issue with SSRS not refreshing parameters, or at least the defaults, even if you specify to always refresh it.
Typically you can force the update by changes the available values.
As an example ...
I set up 2 parameters, the first called PeriodType is a simple text parameter with two available values "Q" and "D", it also has a default value of "D"
The second parameter called StartDate is a Date/Time type.
The following three properties were all set to the exact same expression
Available Values: Specify Values - Label and Value properties
Default Values: Specify Values - Value property
Here is the expression which simply shows todays date if "D" is chosen or the 1st Jan if Q is chosen purely for illustration.
=IIF(Parameters!PeriodType.Value = "D", today(), CDATE("2022-01-01"))
I also set the advanced properties "Always Refresh" option.

Related

SSRS Time expression filter not working with Parameter boolean value

Background:
Trying to achieve a filter in dataset, if the user selects Day shift from the parameter, any data entry between 06:00:00 and 18:00:00 is filter in the report. Furthermore, any data entry between 18:00:00 and 06:00:00 is reflect in the report for Night shift
Process:
I have got a parameter with 2 Boolean values "True" and "False". I have labeled those values as "Day shift" and "Night shift" in the available value Parameter window option. Default value is true.
Converting datetime to time, in the dataset query
SELECT
CONVERT(time, SWITCHOFFSET(CONVERT(datetimeoffset, LastModified),DATENAME(TzOffset, SYSDATETIMEOFFSET()))) as ShiftTime
FROM table abc
Filter expression:=Fields!ShiftTime.Value
Operator: in
Value: =IIf( ( TimeValue(Fields!ShiftTime.Value) >= "06:00:00" And TimeValue(Fields!ShiftTime.Value) <= "18:00:00" ) , Parameters!ShiftType.Value(0), Parameters!ShiftType.Value(1) )
Problem: [BC30516] Overload resolution failed because no accessible
'IIf' accepts this number of arguments
Not sure which part I am going wrong with, I am thinking it is the datatype but unsure.
Solution which I built on
I'm not sure what report designer you are using, but using the Report Designer extension for Visual Studio gives me very different errors.
And it gives errors both in the output window, and the expression window when building it.
Firstly to debug this, add it as a column to your report before you try and implement it as a filter.
Then check the relevant documentation for the function. It turns out the TimeValue function takes a string, not a DateTime, and returns a datetime.
Then, you can't access the available parameter values from the parameter, you can only access the selected parameter values. So instead of Parameters!ShiftType.Value(0) (which has a red line under it) you should just have true (or false depending on which way around your logic is) i.e. the value of the parameter.
Finally, I don't know what implicit conversion SSRS does from strings to a time, so I would do an explicit time compare instead of a string compare. Given we know that TimeValue returns a DateTime with the minimum date value and the time component we can compute the required limites for day/night shift.
The following is what worked for me:
=IIf(TimeValue(Fields!ShiftTime.Value.ToString()) >= DateTime.MinValue.AddHours(6) And TimeValue(Fields!ShiftTime.Value.ToString()) <= DateTime.MinValue.AddHours(18), true, false)
And actually re-visiting it, thats way too convoluted, you are already returning a time value which we can compare directly as
=IIf(Fields!ShiftTime.Value >= new TimeSpan(6,0,0) And Fields!ShiftTime.Value <= new TimeSpan(18,0,0), true, false)
And then your filter should be:
Filter expression: {as shown above}
Operator: =
Value: =Parameters!ShiftType.Value
Note: when you say "between" I don't know whether the intention is to include both 6am and 6pm within the day shift window, but I haven't modified your logic in that regard.

Calling a detail report using the intersection of Row and Column Sum as parameters

Description:
I have a report that that aggregates ATM transactions. This report has a Tablix with the following attributes:
Rows;
Vendor, Terminal.
Columns; Month, Day (Date), Hour.
The Row groups Terminal as child of Vendor and the Column groups Hour as child of Date and Date as child of Month. The Row Group and Column Group properties specify that each child visibility is toggled by its parent and the default if each child visibility to be hidden.
The Placeholder Value property for the intersection is set to Sum() transactions. The Action is set to Go To Report and specifies a detail report that accepts;
Start Date,
End Date,
Vendor,
Terminal
As parameters to the detail report. Each time the link is clicked, it calls the detail report with the dataset parameters set at runtime. So, for “North”, the detail report would reveal 41765 rows associated with the vendor “North”.
Problem:
No matter what resolution of detail in the matrix, when clicking the Sum() value to invoke the detail report, the dataset parameters set at runtime are sent to the detail report. For instance, if I drill down from Month to Date, I see that for Vendor “West” the sum of transactions on 2018-07-01 are 81. If I click that link to summon the detail report, it returns the total rows for the Start Date and End Date (1577 rows), rather than for the Date (81) as expected. This behavior is replicated throughout the intersection combinations.
Request:
How do I call up the detail report such that it returns only those rows specified at the resolution of the intersection in its current state? Ie: the sum at Month\Date: Vendor or the sum at Month: Vendor\Terminal or the sum at Month\Date\Hour: Vendor\Terminal….
What is the best method to accomplish the request? My research has not come up with any valid suggestions. I've attempted to use InScope() in the Placeholder Properties expression but can't seem to get it right.
Thanks for your help!
Your thought is correct, you have to use Inscope
Step 1:
For each parameter you use in your main report to call the subreport use an expression like
= Iif( Inscope("matrix1_Terminal"), Fields!Terminal.Value, Nothing)
For numeric parameters (like month number) set a dummy value like -1 because NULL values are not allowed
= Iif( Inscope("matrix1_Month"), Fields!Month.Value, -1)
Step2:
In the subreport change your parameters to accept NULL values (only for strings and dates)
Step3:
On the subreport adjust your query code to handle dummy parameter values
For string or dates
WHERE (terminal = #Terminal or #Terminal IS NULL)
For numeric values
WHERE (month = #Month or #Month=-1)
Important!!
Don't forget to pass to the subreport other parameters needed like filters in the WHERE of the original report
Tip: In the subreport use temporary string parameters for debugging and pass the values of your Inscope expressions

Updating report parameters for dates based on list

Updating report parameters based on parameter selection? (SSRS)
the above seems to be applicable on list based parameters.
But how do we apply for Dates: say the requirement will be
if i create a list parameters for This day,This week,This month etc. the Start date should change based on earlier selections.
How do we acheive this?
You can set your list parameter to be of type integer, then set available values to be:
Then in your date parameter, set the default value to be along the lines of:
=switch(Parameters!ReportType.Value = 1, dateadd(dateinterval.day, -1, Today()), Parameters!ReportType.Value = 2, DateAdd(DateInterval.Day, 2-WeekDay(Today()), DateAdd(DateInterval.Day, -7, Today())), 1=1, dateadd(dateinterval.day, -1, Today()))
This checks the value of the previous parameter and sets the default start date based on that (weekly or daily). The final condition in the switch is 1=1 - this is always true, so is the equivalent to an else condition. It's not required, I just like it in case something weird happens and they manage to get there.
Note
If you select one of the values from the first parameter (e.g. "Daily") and the default values for the date parameter(s) change, changing the first parameter to "Weekly" will not update the date parameter. This is a known issue with cascading parameters - the only way to change them at that point is to either do it manually or refresh the report.

SSRS Switch statement expression for multi value parameters

I have the following switch statement within an SSRS report, but it errors out when I run the report.
Basically Parameter 1 is a multi value parameter, and when the parameter has two values selected where they are two distinct values, I want a certain text to appear.
=SWITCH(Parameters!Parameter1.Count = 2 AND Parameters!Parameter1.Value(0) = "TEXT1-NY" AND Parameters!Parameter1.Value(1) = "TEXT2-LA" , "Combined (NY & LA)"
, True, JOIN(Parameters!Parameter1.Label,"& ")
)
Additionally, regardless of the numbers that are selected (i.e if there were 6 parameters that were selected), is it possible that these two parameters would be replaced with that particular text followed by , and then names of other parameter values?
First of all, good job working out the expression that you have. You're on the right track, but expressions don't have a programmatic way to loop through the values of the parameter.
One option to do specifically what you asked would be to add a custom function to the Code section of your report that could loop through the parameter values.
Another option would be to simply UNION this "Combined (NY & LA)" value to your dataset so that it is available as one of the options.

SSRS Set Date/Time parameter to NULL based on previous paremeter's selection

I have 3 parameters in an SSRS report: rptFiscalyearId, rptStartDate, rptEndDate.
rptFiscalyearId is a predefined select list of fiscal years.
rptStartDate and rptEndDate are both of type "Date/Time" (i.e., datepickers) and both have "Allow null value" set to true in parameter properties.
The default value of rptFiscalyearId is 0 (meaning "All").
What I'm trying to do is make it so that if the user picks a different value for rptFiscalyearId, then the values for rptStartDate and rptEndDate will both be set to Null.
The only way I'm able to do this is to set the "Available Values" properties in rptStartDate and rptEndDate to an expression like "=IIf(Parameters!rptFiscalyearId.Value > 0, Nothing, Datetime.Now)". However, the problem with this is that by doing so, the parameter is changed to a select list instead of a calendar datepicker.
Is there any way of achieving what I'm looking for without converting my datepicker parameters to select lists?
Is there perhaps some way to do this programatically in the report viewer?
I don't think you can retain the date picker while setting the available values, but have you considered setting the default rptStartDate and rptEndDate values instead? That way, the users would still be to set the values via the date picker - although they would also be able to override the fiscal year start and end dates.