Reporting services: Join all field on a dataset - reporting-services

In a report, I've a dataset with a filter(based on a MultiValue parameter).
This dataset contains two field: Id and Name.
I need to display somewhere the concatenation of all names:
Name1 / Name2 / Name3
The problem is that the join method works only on array, and then I cannot specify a dataset as value.
I looked in custom code too, but I didn't found anything working.
How should I do this ?

I may be a bit late for this but for anyone that's interested in this, there is a rather easy way of doing this in SSRS:
=Join(LookupSet(1,1,Fields!Name.Value, "DatasetName")," / ")

SSRS-2008 R2 and higher...
1. Using LookupSet
If you're beyond the 2008 version OP has, there exists a good solution:
=Join(LookupSet(1, 1, Fields!Name.Value, "DatasetName"), " / ")
Credit for this answer using the LookupSet solution goes entirely to #urbanhusky's answer.
SSRS-2008 and lower...
I'm keeping this answer though because it aggregates #urbanhusky's solution with the solutions available to poor souls stuck with OP's version of SSRS and below.
In SSRS 2008 there's only three "options" as far as I can see, each with its own downside. The first one's probably the least hackish.
2. Extra parameter
Create an internal parameter (e.g. "NameParameter", see this SO answer or MSDN) with Allow Multiple Values. Set the default value of the parameter to the Name field from your dataset. Then use the function =Join(Parameters!NameParameter.Value, " / ") to show the joined names in a textbox.
This may be your best bet, but if there are a lot of values the parameter may not work very well.
3. Use a List
Create a List and drag/drop the Name field to it. If necessary, group on the Name as well.
The disadvantage here is that (AFAIK) the list can't be made to show horizontally.
4. Use a Matrix
Oh boy, this one's real ugly. Nonetheless, here goes: create a matrix, drag the Name field to the column header, and hide the first column as well as the second row (for displaying the data).
The main disadvantage is that it's a hack (and quite some overkill), plus you'll have to trim the last seperator character manually with an expression.

Related

Now you're thinking with parameters; Having a NOT list as a parameter option (report builder 3.0)

I have been super impressed with the way you guys think about parameters in SSRS. You can make them do all sorts of interesting things. I have a report where I want two parameter options reflected in my SQL query, option one is as list of numbers for a certain field. This is easily done via
WHERE [DDI] in #DDI
Setting up the parameter DDI to include the full list of numbers. The point I'm struggling is with the counter case. In essence I need the query to become
WHERE [DDI] not in #DDI
If the second option is picked. I think the best way to solve this is with nested parameters but I can't think with portals sorry parameters in the correct way to figure this out.
TLDR : I want a parameter solution where user can pick between 2 options the first gives them a curated list in a particular field and the second gives everything except that curated list.
You could create a drop down parameter with Include (YES), Exclude (NO) wording. Then in your stored procedure it could filter based on the value passed
WHERE (( #Include = 'YES' AND [DDI] in #DDI) OR (#Include = 'NO' AND [DDI] NOT IN #DDI))
``

LookUp not matching properly

So, I have a problem in Report Builder that is just driving me absolutely crazy.
I have two dataset; one called DS_Grades and the other DS_Pupils. I want to do a simple LookUp based on PupilID, a field that is in both datasets, and return a grade from DS_Grades into a Matrix based on DS_Pupils.
The formula I am using is:
=LookUp(Fields!PupilID.Value, Fields!PupilID.Value, Fields!Grade.Value, "DS_Grades")
I have confirmed that:
1) DS_Grades has the right PupilIds
2) There are actually values in the Grades field
3) Both PupilID fields (I.E. in both datasets) are definitely Integers and not text.
Moreover, if I add a calculated field to DS_Grades called "test" and populated with the value 208301, which is a valid PupilID, then I can enter the below formula and it works fine:
=LookUp(208301, Fields!test.Value, Fields!Grade.Value, "DS_Grades")
So, the LookUp itself must be matching properly, which means that the PupilID fields must be causing the problem, but I have quintuple freaking checked them and they definitely have the right values, in the right format. I am at a total loss as to why SSRS thinks that they don't match.
Help please!
Got it! Some filtering was at Dataset Level (instead of query where I normally do it) that was throwing the whole thing out of joint. Removed that, and it's fine.

Access 2007 - Using results of an equation inside another equation on a report

I inserted three text boxes to test how this could work:
Text81: =1
Text82: =2
Text83: I want this one to be the sum of Text81 and Text82
Thanks in advance for your help on what I think is a pretty simple problem.
There are a couple options that spring to mind.
First you could always modify the data source for the report to include the calculated field.
Second, which is what your question drives at, you can do something like this:
=[Text81] + [Text82]
Should work when typed into the Control Source of a TextBox provided Text81 and Text82 are the data field names from the Data Source of the Report. If they are not you would put the corresponding data field names in the square brackets []
Hope this helps

Adding optional filter in SSRS 2008

I am trying to add an optional filter on a text field in a report. I have tried setting it up in the dataset but it treats it as a required filter so if it is not populated, no results are returned. It needs to use the Like operator. Any advice?
As I was typing out a work-around to this problem, I realized an incredibly easy solution (now that I understand better how it works).
Here's what I did:
Since Hong pointed out that all filter conditions must be met, I reversed my thinking. I moved my existing "IN" filters to the query and fed the parameter directly to the query. Then I created by "LIKE" text filter on the report which a default value of "*" so it would immediately return everything.
Here's what I could've done:
Just the last part. Added the "LIKE" filter with a default value of "*" so it immediately returned everything.
I also agree that most of the time it's best to send the params back to SQL. Since that's not what the OP is asking, here is the best option I have found for doing this. And it is actually quite simple.
Add your parameter with the appropriate data type. Let's use the
example of a "City" in this case (a text/string field).
Check "Allow Nulls" on the parameter.
Add a filter to either a tablix, table or dataset.
In the expression, select the field you want to filter on. Select the appropriate operator, in my example of a data set with Cities, in the Value put in this:
=IIF((Parameters!City.Value Is Nothing), Fields!City.Value, Parameters!City.Value)
I don't think you can make an optional filter in DataSet Properties/Filters, adding filters there means returning results that match ALL filter contiditions, so it is "AND" logical relation among all filters, not "OR".
My sugguestion is to use filter in query designer of the dataset, where you can define "OR" relations to filter out data. For instance: Your_Text_Field="SomeValue" OR Your_Text_Field is Empty.
Although I agree that most of the time it is best to send the parameters back to the stored procedure or data layer to reduce the amount of data returned, I have a case where it is just as easy to do the parameter handling in the RDL file via a filter. Due to this unique situation I found this solution which gives you a way to create an Optional filter in the RDL file.
http://www.andrewshough.com/development/sqlserver/ssrs/optional-filter-in-ssrs/
It is a great blog post with easy step by step instructions on how to create an optional filter.
Please Note: This is NOT my blog but I though this solution was great for what I needed and I hope it helps someone else when they google for "optional filter in SSRS" like I did.
I found a post which solved my problem setting the filter for a report-consumer to a) all multivalue fields being selected so the user b) could specify his/her selection if necessary.
Kasim 8 Dec 2010 8:55 AM #
In reports when we want to default the multivalue parameter to 'Select All' following are the steps.
Open the Report parameter window from the Report menu.
Select the Report parameter from the left handside of the window.
Select 'Multi-value' checkbox and appropriate 'Available values'.
Under default values select 'From Query' radio button'.
Select the appropriate 'Dataset'.
Select appropriate 'Value Field'.
Save the Report and select Preview Tab. You will find all the items selected in the multivalue >parameter list and the result displayed for all the selected items.
found on: http://blogs.msdn.com/b/bimusings/archive/2007/05/07/how-do-you-set-select-all-as-the-default-for-multi-value-parameters-in-reporting-services.aspx
(The Post came up in the comments quite in the middle.)
You can accomplish this by using an expression on the dataset filter.
Check this

How do i represent an unknown number of columns in SSRS?

I'm working on a rather complex report in Sql Server Reporting Services. My SP returns a dynamic number of columns each of which are dynamically named.
Basically think of a time keeping application. Each column that is dynamic represents a time bucket that time was charged to for that team. If no time was charged to that bucket for the period of time the report covers it doesn't show. Each bucket has its own identifier which i need to be the column headers.
I have an SP that returns this all. It does it by doing a bit of dynamic SQL with an exec statement (ugly i know but I'm on SQL 2000 so a PIVOT option wouldn't work)
I can have an indefinite number of buckets and any or all might show.
I found this - http://www.codeproject.com/KB/reporting-services/DynamicReport.aspx - which is helpful but in the example he has a finite number of columns and he just hides or shows them according to which ones have values. In my case i have a variable number of columns so somehow i need the report to add columns.
Any thoughts?
As long as you know a maximum number of columns, it's possible to do this after a fashion.
First, name the columns with a result from your query, so you can either pass it in to the query or derive it there. Second, just build out the report as if it had the maximum number of columns, and hide them if they are empty.
For example, I had to build a report that would report monthly sales numbers for up to a year, but the months weren't necessarily starting in January. I passed back the month name in one column, followed by the numbers for my report. On the .rdl, I built out 12 sets of columns, one for each possible month, and just used an expression to hide the column if it were empty. The result is the report appears to expand out to the number of columns needed.
Of course, it's not really dynamic in the sense that it can expand out as far as you need without knowing the upper bound.
This can be done. I did this and it works fine.
You don't have to know the maximum number of columns or show and hide columns in my approach. Use a matrix and modify your sp to return dynamic data to the structure mentioned in this blog post http://sonalimendis.blogspot.com/2011/07/dynamic-column-rdls.html
Build 2 related Datasets, first one for the report content, and the second one for the list of its column labels.
The Dataset of the report content must have a fixed number of columns and name. You can allocate some maximum number of columns.
In this example I have the first 2 columns as fixed, or always visible, and a maximum of 4 columns to be displayed by choice through a multivalued parameter, or depends on the query conditions. And as usual, we may have a total as well. So, it may look like this:
Fixed01, Fixed02, Dyna01, Dyna02, Dyna03, Dyna04, Total
The second Dataset with its values will look like this:
Name Label
---- -----
Dyna01 Label01
Dyna02 Label02
Dyna03 Label03
I have omitted the 4th Label to demonstrate that not all columns are being used by a certain query condition. Remember that both Datasets are meant to be related to the same query.
Now create a parameter named, say, #columns; populate its Available Values and Default Values with the second Dataset.
For each of those 4 dynamic columns, set the column visibility with the following expression:
=IIf(InStr(join(Parameters!columns.Value,","),"Dyna01"),false,true)
And for each of their column header Text Boxes, use the following expression:
=Lookup("Dyna01", Fields!Name.Value, Fields!Label.Value, "dsColumns")
As for the Total, here is the expression for its visibility:
= IIf(InStr(join(Parameters!columns.Value, ","), "Dyna01"), false, true)
AndAlso IIf(InStr(join(Parameters!columns.Value, ","), "Dyna02"), false, true)
AndAlso IIf(InStr(join(Parameters!columns.Value, ","), "Dyna03"), false, true)
AndAlso IIf(InStr(join(Parameters!columns.Value, ","), "Dyna04"), false, true)
And here is for its values:
= IIf(InStr(join(Parameters!columns.Value, ","), "Dyna01"), Fields!C01.Value, 0)
+ IIf(InStr(join(Parameters!columns.Value, ","), "Dyna02"), Fields!C02.Value, 0)
+ IIf(InStr(join(Parameters!columns.Value, ","), "Dyna03"), Fields!C03.Value, 0)
+ IIf(InStr(join(Parameters!columns.Value, ","), "Dyna04"), Fields!C04.Value, 0)
That's all, hope it helps.
Bonus, that second Dataset, dsColumns, can also hold other column attributes, such as: color, width, fonts, etc.
I think the best way to do it is add all the columns in your table and edit the visibility property of it with the help of arguments that you get from your SP..this will solve the purpose of dynamic column but when viewing the report you will get a lot of white-space which you can solve with SSRS - Keep a table the same width when hiding columns dynamically? and your report will be ready
I've had the need to do this in the past and the conclusion I came to is "you can't", however I'm not positive about that. If you find a solution, I'd love to hear about it.
An issue that comes to mind is that you need to define the report using the names of the columns that you're going to get back from the stored proc, and if you don't know those names or how many there are, how can you define the report?
The only idea I had on how to do this is to dynamically create the report definition (.rdl file) via C#, but at the time, I wasn't able to find an MS API for doing so, and I doubt one exists now. I found an open source one, but I didn't pursue that route.