SSRS Optional Date Parameter extract no rows if null - reporting-services

I have a strange problem with a simple report in SSRS 2008.
my dataset looks like the follwing:
ID
customer
CreationDate
Note
1
AAA
10/20/2022
first order
2
BBB
10/22/2022
second order
3
VVV
10/23/2022
ok
4
XYZ
10/19/2022
changed
5
AAA
10/25/2022
delivered
In my report I have only a Table with all those columns and two parameters: CreationDateFROM and CreationDateTO.
Both parameters are very simple:
On the General tab we have
Data Type: Date/Time
Allow Null value: SELECTED
Allow multiple Value: UNSELECTED
Available Values: NONE
Default Values: NONE
The filter is inside the Dataset (tab Filters) and not inside the source Query.
Now, when I run the report these 2 parameters have the checkbox NULL selected, but the report returns NO ROWS.
Only if I activate the parameters and select some dates, the report works like a charm.
I need to have these paramters OPTIONAL because in the future probably I'm going to insert other parameters (like customer, ID ...)
there is a way to make this report work, keeping these parameters inside the report? I know that if I move those filters in teh query, it works but I have to keep them inside ther report.
thank you in advance!

There are a couple of ways to do this.
You can either set the default dates to some values outside your actual date ranges (e.g. 1st Jan 1900 and 1st Jan 9999) and then turn off the 'Allow Null' option.
The other way would be to change the expression in the dataset filter.
Assuming your 'from' filter says something like .
CreationDate >= #CreationDateFrom
Then change the filer value expression to this for the 'from' filter
=IIF(Parameters!CreationDateFrom.Value Is Nothing, DATESERIAL(1900, 1,1), Parameters!CreationDateFrom.Value )
And this for the 'To' filter
=IIF(Parameters!CreationDateTo.Value Is Nothing, DATESERIAL(9999, 1,1), Parameters!CreationDateTo.Value )
All this does is pass in 1900-01-01 if the from date is null and 9999-01-01 if the to date is null.

Related

Ssrs reporting to default select parameter 2 when some value in parameter 1 is selected

In my report I have 6 parameters. I want parameter 2 to by default select all when I choose some option in parameter 1 and all other parameters stay blank. If I choose parameter 3, then parameter 4 should by default select all. I have tried everything and there is some null problem in it.

How to Combine Fields from Two Datasets SSRS?

I am working on a report to show the total number of hours an employee spent working. Our company tracks labor hours by Service Request and Work Order so I need to bring totals for each into the report.
I created two datasets- one for Work Orders and one for Service Requests. Ideally, I would like to combine the total number of Work Order hours with the total number of Service Request hours and present that number listed by employeeID since both datasets have the employeeID field.
I thought it would be as simple as:
=(SUM(Fields!TOTALHOURS_WO.Value, "DataSet1") + SUM(Fields!TOTALHOURS_SR.Value, "DataSet2"))
I don't get an error, however, I am getting a number which repeats for each employee so I know I'm doing something wrong.
Any help is greatly appreciated.
Mal,
As #StevenWhite mentioned, LOOKUP is probably the function you are looking for.
Here is an example for you. For the example datasets:
EmployeeID | TOTALHOURS_WO
-----------------------------------
123 | 12
456 | 3
EmployeeNum| TOTALHOURS_SR
-----------------------------------
123 | 2
456 | 5
You will note that each table in a SSRS report needs a DataSet assigned to it. I will assume your table is using our first DataSet, which we will name "DataSet1". The second dataset above will be "DataSet2".
For your total hours you will use an expression. It should look something like this:
=TOTALHOURS_WO + LOOKUP(Fields!EmployeeID.Value, Fields!EmployeeNum.Value, Fields!TOTALHOURS_SR.Value, "DataSet2")
So you will be adding the TOTALHOURS_WO from your local dataset to the result from the LOOKUP function. What lookup is doing is taking the first field from your local dataset, finding a match in the dataset provided to the function (as a string), and returning the field from the row it matched to. The last parameter is the dataset to search.
Just in case you get an error... it's always a good idea to cast data to the type you want to work with in case it comes in wrong. So...
=CINT(TOTALHOURS_WO) + CINT(LOOKUP(Fields!EmployeeID.Value, Fields!EmployeeNum.Value, Fields!TOTALHOURS_SR.Value, "DataSet2"))
This assumes you have a one to one match on employee ID. If you have to SUM both fields you can try this:
=SUM(CINT(TOTALHOURS_WO)) + SUM(LOOKUPSET(Fields!EmployeeID.Value, Fields!EmployeeNum.Value, CINT(Fields!TOTALHOURS_SR.Value), "DataSet2"))
SUM for TOTALHOURS_WO will give you the SUM in your current table group (so make sure you are grouping by staff ID in the table). It will then add it to the SUM of LOOKUPSET. LOOKUPSET works the same as lookup but returns an array of matches instead of the first.
Hope this helps.

SSRS 2012 Dynamic Column Number

I got a request from the client when using SSRS reporting Service. I am kind of new to the SSRS. hope that someone can help me out with the problem below.
I use a common example to show the problem.
In SSRS dataset1, the data is like follows
StuId StuSubject
--------------------------------
1 "Math"
1 "Geography"
2 "Science"
3 "Math"
3 "History"
3 "Music"
In the SSRS dataset2, the data is like this one
StuId StuName
------------------------
1 "Tom"
2 "Joseph"
3 "Linda"
In the SSRS DataSet3 , it would be like
StuId StuInt
--------------------------
1 "Swim"
2 "Chess"
2 "Swim"
2 "Running"
3 "Game"
What i want in the SSRS report would be like this one
StuId StuName StuSubject StuSubject StuSubject StuInt StuInt StuInt
1 "Tom" "Math" "Geography" NULL "Swim" NULL NULL
2 "Joseph" "Science" NULL NULL "Chess" "Swim" "Running"
3 "Linda" "Math" "History" "Music" "Game" NULL NULL
The tricky part is that I don't know what is the maximum number of StuSubject for all these students, or more precisely, I don't like to set the limit of the 'StuSubject' columns because there could be hundred columns in the real case. I have thought of LookupSet function, but seems using LookupSet, you can only join multiple StuSubjects values with "," in one cell.
Any advice / suggestion would be much appreciated and thanks in advance
Edit : I could use Matrix control for one "join" situation, but is this possible to "join" multiple datasets into one finale one ?
The solution for you is to use Matrix report item - it allows to perform data grouping by rows and columns. Your data, returned from DB, should be aggregate of those two datasets that you have - it should be set of rows in format (StuId, StuName, StuSubject).
You can then add row grouping by StuId (and child row grouping by StuName, but this is not necessary), and add column grouping by StuSubject. Details cell will simply output StuSubject.
Notice that although Lookup* functions allow you to do join data while processing the report, they are run while processing report by SSRS and thus are certainly less efficient (from my experience expressions almost always have really bad impact on report performance). Also, doing join whikle processing report is not a canonical way to develop the report, and not the best way to use SSRS engine, which works good when you need simple grouping or do not need grouping at all. The best approach is to generate SQL result as much close to what you want to display, as it is possible, taking into account context of report and common sense of course.
Follow the below steps:
Use your DataSet1 in your matrix as suggested approach from LINK.
Your query would be similar to below:
Select StuId,StuSubject
'StuSubject' + Cast(row_number() over (partition by id order by score) as INT) StuSubjectVal
from table
You should get the result like below (after using matrix).
StuId StuSubject1 StuSubject2 StuSubject3......
Add a column to your matrix, and use the Lookup from DataSet1 to DataSet2.
=Lookup(Fields!StuId.Value, Fields!StuId.Value, Fields!StuName.Value, "DataSet2")
Have not tested it, but it should work.

Interactive sorting In SSRS on Values - Matrix report

I want a interactive sorting in SSRS matrix report. From database we are getting 3 columns -PrimaryKey,Columns and Value.
We are grouping rows by Primary Key and grouping column by Columns and use Value as data.
My Matrix Report -
ID [Columns]
[Primary Key] Values
Output of the Matrix report -
ID FirstName MiddleName Lastname
1 Rajiv Jha Sharma
2 Prem Kumar Bose
3 Usha Shamila Praveena
I am able to use the interactive sorting on ID because ID is group by rows but I want to use the interactive sorting on dynamic cloumns values like FirstName,MiddleName and LastName.
Expected result when we interactive sort on Lastname
ID FirstName MiddleName Lastname
2 Prem Kumar Bose
3 Usha Shamila Praveena
1 Rajiv Jha Sharma
Thanks for any Help.
Are you using the report wizard to build this? You should be able apply the interactive sort using the properties menu on the column groups.
By adding an interactive sort button to a column header you can allow a user to click the column header and sort the parent group rows in a table or matrix by the value displayed in that column. The order of child groups remains unchanged.
To add an interactive sort button to a column header to sort groups:
In a table or matrix on the report design surface, right-click the text box in the column header for the group to which you want to add an interactive sort button.
Click Text Box Properties.
Click Interactive Sort.
Select Enable interactive sort on this text box.
In Sort, click Groups.
From the drop-down list, select the name of the group that you are sorting. For groups based on simple group expressions, the Sort by value is populated with group expression.
For more info, see this article: http://technet.microsoft.com/en-us/library/cc627509(v=sql.100).aspx
Quite an old question, but I stumbled upon similar problem recently.
Though SSRS does not allow you to add interactive sorting on dynamic columns in a matrix, you can simulate similar behaviour. I've figured out a method, which require the report to fire itself (through go to report action) sorted on desired column.
I will use a bit more complicated example to show the full functionality of this solution.
Imagine an online bookstore, which would like a report showing their customers (rows), number of books (values) and total value of books (values), which they bought, by category – Fiction/NonFiction in my example (columns). Of course they want to see their best customers, so the sort will be descending.
Example data that we are getting from the database:
UserID Columns BooksCount BooksValue
AliBaba Fiction 2 25.96
AliBaba NonFiction 4 112.00
ThomasJefferson Fiction 3 36.83
ThomasJefferson NonFiction 1 46.80
BillCosby Fiction 10 536.47
BillCosby NonFiction 2 26.87
The report will look like this:
[Columns]
Books Count Books Value
[UserID] Values Values
I would like the report to be able to sort by “Books Count” or “Books Value” for any Column. Here are the steps to follow:
You need to add parameters that will store the name of the column to sort on - #SortColumn and the metric name (counts or values) to sort on - #SortMetric.
Go to “Books Count” textbox and add action "Go to report" specifying the same report. Add #SortColumn parameter with a value from [Columns] field in the underlying dataset. Add #SortMetric parameter with value set to “BooksCount”. Similar for “Books Value” textbox.
You can adjust the column header text with following expression, which will show the user on which column data is sorted:
= IIf( Parameters!SortColumn.Value=Fields!Columns.Value And Parameters!SortMetric.Value = "BooksCount" ," ^","")
This was for “Books Count”, you can add similar for “Books Amount”
Finally the magic that happens on the database site. Source table is named [Sales]. Apart from the sorting, below code allows to select only top N rows if your dataset is larger.
You can create a dataset using this code or better create a stored procedure. And join report parameters with dataset parameters.
DECLARE #TopN INT = 50
;WITH Users_Sorted AS
(
SELECT
UserID
,ROW_NUMBER() OVER (ORDER BY
CASE #SortMetric
WHEN 'BooksCount' THEN Sales.BooksCount
WHEN 'BooksValue' THEN Sales.BooksValue
END DESC) AS ROWNO
FROM Sales
WHERE
Sales.Columns = #SortColumn
)
,Sales_MAIN AS
(
SELECT
Sales.UserID
,Sales.Columns
,Sales.BooksCount
,Sales.BooksValue
,ISNULL(Users_Sorted.ROWNO,
ROW_NUMBER () OVER (PARTITION BY Sales.Columns ORDER BY Sales.UserID ASC)
) AS ROWNO
FROM Sales
LEFT JOIN Users_Sorted ON Sales.UserID = Users_Sorted.UserID
)
SELECT * FROM Sales_MAIN WHERE ROWNO <= #TopN ORDER BY ROWNO

Column selection in multiple columns by using single click?

My report look like below
Region1 Region2 Region3 Region4 Region5 state1 state2 state3 state4 state5
I have created column selection parameter and Region value 0
State value 1
How I need to make changes if I select Region only regions 1 to 5 are displayed, or if I select State only states 1 to 5 are displayed?
Can you please help me guys I have been stuck for 3 days. I tried of selecting using single column selection by using below
expression =iif(instr(Join(Parameters!ColumnSelect.Value,","),"01")>0,false,true)
But i am unable select 5 columns at a time.
I think your expression should be:
= Not(Join(Parameters!ColumnSelect.Value,",").Contains("0"))
I would be applying that as the Column Hidden Expression for the Region columns. A similar expression (with the "0" changed to "1") should work for the State columns.
Set the Hidden Condition of each column individually. Make sure you are selecting the columns under Column Groups in the Advanced Mode of the Grouping Window:
Region Columns Hidden Condition:
=Join(Parameters!ColumnSelect.Value,",") not like '*0*'
State Columns Hidden Condition:
=Join(Parameters!ColumnSelect.Value,",") not like '*1*'
I am using below expression
=IIF(instr(Join(Parameters!ColumnsSelect.value,", "),"0")=0,True,False)
=IIF(instr(Join(Parameters!ColumnsSelect.value,", "),"1")=0,True,False)