views:

131

answers:

3

Customer wants me to repeat the parameter values in the page header of the report. But if they just choose "Select All" on a multi-valued parameter, they want the text "Any" listed.

For example, one parameter has a fixed set of 9 values. I hard-coded the expression for a text box to:

="Room Size: " &
iif(Parameters!pRoomCap.Count=9,
    "Any",
    Join(Parameters!pRoomCap.Value, ", "))

How can I do this if the parameter source is a query of unknown size?

+1  A: 

Can you compare the count of the parameter to the count of the dataset you pull the parameter values from?

jimconstable
Err Msg: CountRows cannot be used in the Page Header or Footer. I am quickly developing bad feelings toward SSRS.
Bill
A: 

I unioned my dataset for the parameters with one which I created manually with a "select" statement - I was then able to force the value to be something like -1 or null.

Then simply check if the parameter contains -1 or null and replace the value in the header with the replacement text.

Mauro
+3  A: 

Try this out. You need to compare the total number of parameters in the dataset to the count of selected parameters. The following assumes that your multivalue parameter is using a dataset called "dsRoomSizes"

="Room Size: " 
& iif(Parameters!pRoomCap.Count = count(Fields!pRoomCap.Value,"dsRoomSizes"),
"Any", 
Join(Parameters!pRoomCap.Value, ", "))

This expression will work in the page header/footer.

UPDATE

In the interests of finding a solution to your problem, the following should work for you. It feels hackish and I encourage you to keep research alternative methods but this will work:

  1. Create a second multivalue parameter and name it something like "pRoomCap_hidden".
    • The source of the parameter is the exact same query
    • In the parameter properties, setting the default values to the same query
    • Important: Set the parameter visibility to hidden

This will create a second multivalue parameter in your report that is exactly the same as your initial multivalue parameter only this parameter list will have all values selected by default.

Enter the following expression in a textbox in your header:

=IIF(Parameters!pRoomCap.Count = Parameters!pRoomCap_hidden.Count,"All",Join(Parameters!ReportParameter1.Value,", "))  

The above will compare the selected values in each parameter list. If the lists contain the same selected values then that indicates that "All" have been selected in the first list.

Like I said, it is hackish but it definitely works. Until you are upgraded to 2008, this might not be a bad workaround for you.

Alison
Sorry. Count(Fields!Division.Value, "dsDivision") gives me an error "fields cannot be used in page headers or footers." Tried this and it returned "Nothing", so my I don't think this approach will work. =iif(isnothing(Count("dsDivision")), 0, count("dsDivision"))
Bill
I have this working in a page header. Try creating a new empty report with nothing other than your multivalue parameter and the expression above. You'll see that it works.
Alison
I just retested and it is definitely working for me in the header. Can you give more information about your dsDivision dataset?
Alison
Maybe it is 2005 vs 2008 thing. If this works in SSRS 2008 than you win the bounty, but I have 2005 and it doesnt. Have dumb workaround for now, and will fix when we upgrade next year.
Bill
Hmmm...interesting. I don't have 2005 to test (we're on 2008.) It feels like it should work for you. It's not like you're trying to do anything too far outside the box. The fact that you see the error when putting the Fields in the header is interesting. You can't put a single field in the header but you most definitely can do aggregate count of fields int the header. I can't imagine that this is related to 2005. I want to figure this out because it feels like the solution is right there.
Alison
@Alison: genius. A fine hack, I might add. I wish the SSRS engine was a little better about caching queries, because your Edited solution is godawful slow, but it definitely works. Thanks
Bill
I'm glad it's working for you. Does the query really take that long to run? Both parameters should be using the same single dataset. I would expect that performance wouldn't be so negatively affected.
Alison