Fields cannot be used in report parameter expression
Asked Answered
E

3

8

I have to set the start_date of my report depending of a report parameter. The time stamps are calculated in a database query.

My expression looks like this:

=SWITCH (
    Parameters!report_type.Value = 1,First(Fields!daily_start.Value, "Timestamps")
    ,Parameters!report_type.Value = 2,First(Fields!weekly_start.Value, "Timestamps")
    ,Parameters!report_type.Value = 3,First(Fields!monthly_start.Value, "Timestamps")
)

Unfortunately I get the error message:

A value expression used for the report parameter 'time_from' refers to a field. Fields cannot be used in report parameter expression

I know, that this is not allowed because SSRS cannot be sure in which order datasets are called. But I think this is not dangerous.

All time stamps are received by query without parameter. The parameter report_type is selected by a user before the report will be generated.

Can someone give me a hint for a workaround?

Epilimnion answered 27/11, 2012 at 8:35 Comment(1)
Could you use fixed hidden parameters for your daily_start, weekly_start, monthly instead of fields ?Ngocnguyen
C
4

Here's the workaround - get the value using SQL.

Create a new Dataset called StartDates:

SELECT CASE 
    WHEN @report_type = 1 THEN daily_start
    WHEN @report_type = 2 THEN weekly_start 
    WHEN @report_type = 3 THEN monthly_start
END AS StartDate
FROM MyTable

You already have the @report_type and @time_from parameters. With the @time_from parameter, set its Default Values to Get values from a query using the StartDates dataset and the Value field StartDate.

Now, you'd think this might be enough to make it work - you're referencing this query as the default value and as you change the @report_type parameter the other parameters refresh, but the first date in the @time_from parameter never changes. That's because the refresh happens on the Available Values query, not on the Default Values query.

So you also need to wire up the Available Values query to the StartDates query. Now your query will fire on the change of @report_type and the default value will be set to the appropriate date for your selection.

Claudicant answered 27/11, 2012 at 23:34 Comment(1)
what if i can only do this in fetchxml?Delgado
S
2

I switched from a query to Stored Procedure and was getting this error. Things I tried:

  • Ensured I had sufficient permission on the database (you need EXEC rights or DBO to run teh sproc)
  • Delete the existing parameters (and then use refresh fields to refresh/get the correctly named ones back)
  • Remove the square brackets around the stored procedure if you've specified that
Surround answered 17/7, 2014 at 7:2 Comment(1)
Removing square brackets around the Procedure worked for me. Thanks!Salutatory
P
0

Sometimes, Expressions can get a bit verbose. I have created a Report Code Function and then used that as the Parameter Value.

For example, I created a Code function called "CalculateDateSet" and then set the Report Parameter to this expression:

"=Code.CalculateDateSet(Parameters!Month.Value, Parameters!Year.Value"

Pika answered 1/9, 2015 at 14:19 Comment(1)
Could you be so kind as to elaborate a bit on your proposed workaround?Miserere

© 2022 - 2024 — McMap. All rights reserved.