Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

Syntax Expand / Collapse
Author
Message
Posted Thursday, May 16, 2013 1:55 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Friday, September 26, 2014 4:50 AM
Points: 24, Visits: 56
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.
Post #1453357
Posted Friday, May 17, 2013 1:19 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: 2 days ago @ 4:27 AM
Points: 23, Visits: 145
Do you get any error-messages? Is the textbox stand-alone or part of a tablix?
Post #1453872
Posted Friday, May 17, 2013 1:45 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Friday, September 26, 2014 4:50 AM
Points: 24, Visits: 56
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.
Post #1453882
Posted Friday, May 17, 2013 3:42 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: 2 days ago @ 4:27 AM
Points: 23, Visits: 145
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!


  Post Attachments 
Test.rdl.txt (0 views, 288.36 KB)
Post #1453914
Posted Friday, May 17, 2013 4:23 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Friday, September 26, 2014 4:50 AM
Points: 24, Visits: 56
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.
Post #1453921
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse