locked
Variable values cannot be used in aggregate functions. RRS feed

  • Question

  • I have two report variables to store the start date time and end date time of my report, which are calculated by a call to some methods of my custom assembly. For example if the user selects to run a report against the previous 60 minutes, the custom assembly would calculate the start date time and end date time based on the current date time.

    I store these in the report variable to have them remain constant when exporting; exporting seems to create a new instance of the custom assembly. So when I didn't use the report variables the start date time and end date time would be recalculated and the the report date time range would be different in the exported result; but the dataset wasn't updated so the exported report date time range was incorrect. 

    Like I said to fix this I store the start date time and end date time in report variables. As reported in this article: http://technet.microsoft.com/en-us/library/bb934256.aspx:

    The value for a report variable is set once and then remains unchanged during report processing.

    This seems to old true even when exporting the report.

    Now I need to pass the start date time variable and end date time variable to another assembly method, but if this method call falls within an aggregate funtions (for example in a matrix subtotal expression) I get the following error: 

    [rsAggregateofVariable] The Value expression for the textrun 'textbox26.Paragraphs[0].TextRuns[0]' contains a variable reference in the argument to an aggregate function (or RunningValue). Variable values cannot be used in aggregate functions.

    My question is, if the report variable is set once and then remains unchanged during report processing, then why couldn't I be allowed to use it in an aggregate function?

    Friday, February 6, 2009 3:11 PM

Answers

  • Hello Emmanuel,
     
    a variable value in RS 2008 may reference aggregate functions in its original calculation (and as a result may be calculated interleaved with other aggregates).  

    That's why the value currently cannot be referenced from within another aggregate function - we are looking into lifting that restriction in a future release.  In the meantime, could you pass the variable value directly as a separate argument into your method call, instead of being used in the RunningValue function?

    HTH,
    Robert
    Robert Bruckner   http://blogs.msdn.com/robertbruckner
    This posting is provided "AS IS" with no warranties, and confers no rights.
    Saturday, February 7, 2009 6:57 PM
  •  Hello Emmanuel,

    report variables are allowed to reference dataset scope aggregates, e.g. =Sum(Fields!Sales.Value, "Dataset1").  That's why this restriction is present there as well.

    On export from within the current session, aggregate values won't be recalculated the same way that variable values are not recalculated.

    HTH,
    Robert


    Robert Bruckner   http://blogs.msdn.com/robertbruckner

    This posting is provided "AS IS" with no warranties, and confers no rights.

    Tuesday, February 10, 2009 6:41 PM

All replies

  • Hello Emmanuel,
     
    a variable value in RS 2008 may reference aggregate functions in its original calculation (and as a result may be calculated interleaved with other aggregates).  

    That's why the value currently cannot be referenced from within another aggregate function - we are looking into lifting that restriction in a future release.  In the meantime, could you pass the variable value directly as a separate argument into your method call, instead of being used in the RunningValue function?

    HTH,
    Robert
    Robert Bruckner   http://blogs.msdn.com/robertbruckner
    This posting is provided "AS IS" with no warranties, and confers no rights.
    Saturday, February 7, 2009 6:57 PM
  • Hi Robert,

    Thanks for the response.

    I understand that a group variable could reference an aggregate function, but does this hold true for a report variable?

    I did get around the issue by passing a call to the method that calculates the start and end date times as argument of the method call in the aggregate function. In my custom assembly if the start date time and end date time are already initialized they will not be recalculated.

    I was just concerned that I could fall into a scenario where I would have a new instance of the custom assembly, for example when exporting the report; in this scenario would the report variable show the original start and end date time and the aggregate function would get a newly calculated start and end date time?

     

    Thanks,

    Emmanuel

    Tuesday, February 10, 2009 2:45 PM
  •  Hello Emmanuel,

    report variables are allowed to reference dataset scope aggregates, e.g. =Sum(Fields!Sales.Value, "Dataset1").  That's why this restriction is present there as well.

    On export from within the current session, aggregate values won't be recalculated the same way that variable values are not recalculated.

    HTH,
    Robert


    Robert Bruckner   http://blogs.msdn.com/robertbruckner

    This posting is provided "AS IS" with no warranties, and confers no rights.

    Tuesday, February 10, 2009 6:41 PM
  • Hi Robert,

    Thanks for the explanation, it makes more sense to me now.

    Emmanuel
    Tuesday, February 10, 2009 8:49 PM