May 16, 2013 at 1:55 am
Folks,
Can anyone see what's wrong with the following? It's been bugging me for ages as I can't see any problem withit.
=First(Fields("gradient_colour" & Fields!Response.Value).Value, "uspGetReportSettings")
This is setting the background colour of a textbox. The value in the text box is percentage from the dataset "feedbackResults", Response is a column from that dataset. uspReportSettings is a generic sp that returns all the report settings in a single row. In this instance, Response returns 5 and when I call:
=First(Fields("gradient_colour5", "uspGetReportSettings")
It works fine.
May 17, 2013 at 1:19 am
Do you get any error-messages? Is the textbox stand-alone or part of a tablix?
May 17, 2013 at 1:45 am
Hi dohnfors,
Yes, it's part of a tablix
The error is:
The BackgroundColor expression for the text box 'response_perc' referes to the field 'Response'. Report item expressions can only refer to fields within the current dataset scope or, if inside an aggregate, the specified dataset scope.
However the dataset for the tablix is the dataset containing the Response column. The tablix displays the percentages of each response and the response column is displayed within the tablix, so it's defo not out of scope.
May 17, 2013 at 3:42 am
The problem is that the aggregate is bound to the dataset "uspGetReportSettings". Everything inside that aggregate (between the two parenthesis) is calculated with that scope and the field "Response" doesn't exists in that dataset.
I would try another approach based on this article http://blogs.msdn.com/b/bwelcker/archive/2007/07/11/laser-guided-missiles-report-localization-through-parameters.aspx.
1. Unpivot your dataset "uspGetReportSettings" so there is one row for each setting instead of one column:
Setting Value
gradient_colour1 Red
gradient_colour2 Blue
... ...
2. Create a hidden multivalued parameter based on that dataset with setting as label and Value as value. Set the default values to the same dataset and the Value field to 'Value'.
3. Copy and paste this code to custom code:
Public Function GetReportSetting(P as Parameter, Label as String) as String
Dim i As Integer
For i = 0 to Ubound(P.Value)
If (P.Label(i) = Label) Then Return P.Value(i)
Next i
Return Label
End Function
4. Use the code below to change the background color:
Code.GetReportSetting(Parameters!uspGetReportSettings, "gradient_colour" & Fields!Response.Value)
Check out the attached file for an example!
May 17, 2013 at 4:23 am
Thanks dohnfors,
I hadn't realised that the scope of the aggregate would override in that context.
I understand your solution, I've used that method for internationalisation of text. I think in this case though, it would require an awful lot of changes to achieve a minimal gain. I can code around it with a switch statement for this particular issue. Definitely worth bearing in mind for the future though.
Thanks for your help.
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply