Claus on Code

A data dudes random musings about code, bugs, products, life etc.


[rsAggregateOfMixedDataTypes] The Value expression for ‘x’ uses an aggregate function on data of varying data types. Aggregate functions other than First, Last, Previous, Count, and CountDistinct can only aggregate data of a single data type

Yet another irritating error message from reporting services 🙂

You will typically get that error, when you try to create a calculated member in the visual designer like so:

IIF( [Measures].[x]=0 , [Measures].[y] , 0,00)

And then use the SUM or another aggregate function on the new measure.

If you create the same calculated member in pure MDX, and run it in for instance management studio, it will not yield any errors. Like so:

WITH MEMBER [Measures].[z] AS
IIF( [Measures].[x]=0 ,
[Measures].[y] , 0,00)

Just to describe the calculated member in words. If the measure x equals 0, then the new measure z will be the value of the measure y, and if the measure x not equals 0, then the new measure z will take the value of 0,00.
The problem is that, when reporting services SUM the new measure z, it Sums data from y and 0,00, and reporting services will in some cases see the values as different data types. In my example the measure x was a decimal, and reporting services interpreted the 0,00 as an integer.

To avoid this problem, you have to tell reporting services that 0,00 is a decimal like this:

IIF( [Measures].[x]=0 , [Measures].[y] ,  Cdec(  0,00))



4 responses to “[rsAggregateOfMixedDataTypes] The Value expression for ‘x’ uses an aggregate function on data of varying data types. Aggregate functions other than First, Last, Previous, Count, and CountDistinct can only aggregate data of a single data type”

  1. Great solution – worked perfectly and I had been working on this problem for hours!

    Thanks!

  2. Thanks. I’m converting from Crystal Reports to SSRS and thought I was doing something wrong. The info you provided fixed things.

  3. THANK YOU! I’m new to SSDT and this error was driving me crazy. So much for implicit type conversion…

  4. what will happen if the x value is changed to 1?

Leave a Reply

Your email address will not be published. Required fields are marked *