I need to create a report using SSRS, it needs dynamicly group by the matrix.
I added a parameter(name: ColumnData) for it and the available value like 'Date', 'Type', 'ServerName',
for a single value, I can edit the group by expression to
=Fields(Parameter!ColumnData.Value).Value
but when the parameter is multiple, Parameter!ColumnData.Value would return a list and I need to use like that:
==Fields(Parameter!ColumnData.Value(0)).Value & Fields(Parameter!ColumnData.Value(1)).Value
but it's not what I want as I need to indicate the index manually...
Anyone knows how to use the multiple parameters in the group by expression?
Thanks a lot!
If you deselect 'Allow multiple values' in the Parameter properties, your group by expression should work as is.
You will then be able to group by the selected value from the parameter.
(It will then not be possible to choose more than one of the values).
But it only makes sense to group on one value, or?
I stumbled on this topic, but my solution was simple. I had to group by multiply fields, and ended using something like this:
<GroupExpression>=Fields!ColumnName1.Value</GroupExpression>
<GroupExpression>=Fields!ColumnName2.Value</GroupExpression>
<GroupExpression>=Fields!ColumnName3.Value</GroupExpression>
But this may not be what you are looking for since you wanted something more generic.
You can check this answer as it has some advices about matrix:
Multiple group expressions in list (ssrs 2005)
Hope that helps.
Related
My goul would be to implement a parameter #Grouping with two possibilities: Vendor / Product
With the parameter I need to change the grouping of my data, not only in calculateing the data but also in the sorting of the columns:
Do I need to use executable SQL and calculate everything outside the report and use dynamic columns like "Column1=Vendor, Column2=Product if Parameter=Vendor" to place them in the Tablix?
Or is it possible to manage all this in the report using grouping properties? If so, unfortunately I am not very familiar with the grouping expressins and would thank you for detailed answers.
I was able to use the parameter :)
With Vendor beeing my default first Group, I made a Right-Click on the Group in the GroupingBox. In the General section I added an Expression on the "Group on":
=IIf(Parameters!Grouping.Value = "Vendor", Fields!Vendor.Value, Fields!Product.Value)
On the child group Product I did the opposit:
=IIf(Parameters!Grouping.Value = "Vendor", Fields!Product.Value, Fields!Vendor.Value)
The same expressions I used in the Sorting section. And also in the fields on the Tablix.
Thank you.
I am trying to sum two same fields, from two different Tablix's.
Both Tablix's filter for different building names. "Mydata" is the name of my dataset.
=Sum(Fields!TotalFloorArea.Value,"Mydata") +Sum(Fields!TotalFloorArea.Value, "Mydata")
How do I reference the different Tablix?
Many thanks in advance.
There is more than one way to accomplish this. One approach is to use an IIf() as part of each of your SUM() calls. Using the IIf() condition(s) you will be repeating the condition(s) used to filter your two Tablix controls.
Try something like this:
=Sum(IIf(Fields!BuildingName.Value = "BLDG-A",
Fields!TotalFloorArea.Value,
0), "Mydata") +
Sum(IIf( Fields!BuildingName.Value = "BLDG-B",
Fields!TotalFloorArea.Value,
0), "Mydata")
I prefer to use Report Variables for this. Define a couple of report variables totalBuildingA and totalBuidlingB and use the expressions above for the individual variable's expressions:
totalBuildingA
=Sum(IIf(Fields!BuildingName.Value = "BLDG-A",
Fields!TotalFloorArea.Value,
0), "Mydata")
totalBuildingB
=Sum(IIf(Fields!BuildingName.Value = "BLDG-B",
Fields!TotalFloorArea.Value,
0), "Mydata")
Then you can add the two report variables together to get the equivalent result as the first example, (but with code that is a lot more flexibile for combining the SUMs for two or more other Building Names etc):
=Variables!totalBuildingA.Value + Variables!totalBuildingB.Value
I got this to work now. I added a row Outside the group below then added Totals into Rows. Then for grand total I referenced the textboxes for example Reportitems!Textbox22 + Reportitems!Textbox23.
I'm not sure this makes sense. But now working! Just trying to work out the final formulas.
Referring to textboxes can get messy. And there's no direct way to reference sums from other groups or tables. A good option that will work for this is to add calculated fields to your dataset. You can have one for the 1 building value and another for the other 25 buildings. The expression would look something like this:
=IIf(Fields!BuildingName.Value = "BLDG-A", Fields!TotalFloorArea.Value, Nothing)
That way you can sum those calculated fields from anywhere in the report. You don't need to specify the scope in your Sum function, let it use the current scope for the cell like this:
=Sum(Fields!BldgA_TotalFloorArea.Value)
I have a master that can be filtered using 4 different parameters. I used a iif statement to join all the parameters to filter the report.
The problem I am now having is when more than one paramater is selected, it tends to return values for the first parameter rather than for all
My paramter expression is as follows:
expression
iif(IsNothing(Parameters!Div.Value)=0,Parameters!Div.Value
,iif(isnothing(Parameters!St.Value)=0,Parameters!St.Value
,iif(isnothing(Parameters!Sp.Value)=0,Parameters!Sp.Value
,Parameters!Hc.Value)))
values
=iif(IsNothing(Parameters!Div.Value)=0,Parameters!Div.Value
,iif(isnothing(Parameters!St.Value)=0,Parameters!St.Value
,iif(isnothing(Parameters!Sp.Value)=0,Parameters!Sp.Value
,Parameters!Hc.Value)))
Any help will be helpful
I think what you are trying to do is something like this:
=IIF(NOT ISNOTHING(Parameters!Div.Value), Parameters!Div.Value,
IIF(NOT ISNOTHING(Parameters!St.Value), Parameters!St.Value,
IIF(NOT ISNOTHING(Parameters!Sp.Value), Parameters!Sp.Value,
Parameters!Hc.Value)))
Do you only want to check for one value?
I usually check each parameter separately so it uses all of them at once. Though there may be a situation where your theory is what you want.
If you want to evaluate all the parameters, just add them to the FILTER of the dataset, table, or group. Choose your field in the Expression and the Parameter in the Value.
I need to be able to set an SSRS parameter to contain multiple values.
In TSQL, I can have a where clause that states:
where Attribute in ('Value1', 'Value', 'Value3')
What I need is in SSRS to have:
where Attribute in (#Attribute)
Where I am getting hung up is how to format the parameter value expression so that SQL sees it as: 'Value1', 'Value', 'Value3'
I have had some luck making the where clause look at only the first value, but I need it to look at all 3. How would I format the expression to do that?
I would just allow it to accept multiple values, and check each value individually, but I need the drop down list to have groups. So, if the user selects GroupA, the where clause uses: IN ('Value1', Value2') and if the user selects GroupB, the where clause uses a different list for the IN.
Hopefully it's just a matter of formatting the expression correctly.
Well, if you didn't have the requirements about groups, this wouldn't be an issue since all you need is to make your parameter a multi-valued one, and on your dataset query do WHERE Attribute in (#Attribute). But taking that requirement into account, the only way I can think of, is to have two multi-valued parameters: #Group and #Attribute. You'll need to make #Attribute not visible and create a dataset to populate it. That dataset would be something like this:
SELECT Attribute
FROM Attributes
WHERE Group IN (#Group)
And create another dataset for your report data:
SELECT <all your data>
FROM YourTable
WHERE Attribute IN (#Attribute)
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