SPLady
asked on
Percentage is SSRS 2005
How do you sum or average % in SSRS getting the error below when =Sum(Fields!ShipmentPercen tage.Value ) however (Fields!ShipmentPercentage .Value) works fine.
Build complete -- 0 errors, 0 warnings
[rsAggregateOfMixedDataTyp es] The Value expression for the textbox ‘textbox26’ 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.
Preview complete -- 0 errors, 1 warnings
Build complete -- 0 errors, 0 warnings
[rsAggregateOfMixedDataTyp
Preview complete -- 0 errors, 1 warnings
ASKER
Thank you @devlab2012 but it is not working.. Question.. Why CDbl?
Hi
Cdbl converts to double..... Is your shipment percentage true numeric value? (eg doesn't contain % in it?)
Regards
Emil
Cdbl converts to double..... Is your shipment percentage true numeric value? (eg doesn't contain % in it?)
Regards
Emil
ASKER
it the report it has %.. the data was created at the report level
Hi
In your post you refer to Fields! Is your percentage calculated field in the dataset? I don't fully understand "created at the report level".
If you don't mind I will try to make it clearer and provide some more explanations and extra info.
This one will always work (reason? it doesn't matter what data type is"
=Fields!ShipmentPercentage .Value
This one has certain conditions to work:
=SUM(Fields!ShipmentPercen tage.Value )
1) SUM expects numeric data type so
a) You need to provide numeric data (eg. 1% + 2 will not work as it is like A + 2 and should be 1+2)
b) If you query returns string then you might have to explicity convert it to specific data type so you avoid confusion. Data types are very important for instance integers and decimals should be treated differently the same with string. Real life example is float data type you don't use with small precisions because you encounter rounding issue and if you get 1cent or 1p (£) difference then it is not much but multiplying by 10000000 occurances does make a difference.....
c) If your results contain sometime % then you have to apply text manipulation funtions to take it out and convert to number.
Hope that helps
Emil
In your post you refer to Fields! Is your percentage calculated field in the dataset? I don't fully understand "created at the report level".
If you don't mind I will try to make it clearer and provide some more explanations and extra info.
This one will always work (reason? it doesn't matter what data type is"
=Fields!ShipmentPercentage
This one has certain conditions to work:
=SUM(Fields!ShipmentPercen
1) SUM expects numeric data type so
a) You need to provide numeric data (eg. 1% + 2 will not work as it is like A + 2 and should be 1+2)
b) If you query returns string then you might have to explicity convert it to specific data type so you avoid confusion. Data types are very important for instance integers and decimals should be treated differently the same with string. Real life example is float data type you don't use with small precisions because you encounter rounding issue and if you get 1cent or 1p (£) difference then it is not much but multiplying by 10000000 occurances does make a difference.....
c) If your results contain sometime % then you have to apply text manipulation funtions to take it out and convert to number.
Hope that helps
Emil
Do you mean you have character "%" inside your Fields!ShipmentPercentage. Value?
If this is the case you can try doing the following
=Sum(CDec(Replace(Fields!S hipmentPer centage.Va lue,"%","" ))
If this is the case you can try doing the following
=Sum(CDec(Replace(Fields!S
ASKER
@itcouple excuse my terminology.. The % calculation was made during the report creation
ASKER
@Alfred1 Thank you so much but, It is not working
OK. What is the error you are getting if it is not working? Can you provide sample values for Fields!ShipmentPercentage.
ASKER
I am getting NaN or in the sum field there I am using this expression
=iif(Fields!ShipmentPercen tage.Value >0,avg(Fie lds!Shipme ntPercenta ge.Value), 0) (sum or average doesnt work)
In the records field I am using (that is working)
=iif(Fields!ShipmentPercen tage.Value >0, Fields!ShipmentPercentage. Value, 0)
=iif(Fields!ShipmentPercen
In the records field I am using (that is working)
=iif(Fields!ShipmentPercen
OK. You are getting a NaN. The question is why are you getting a NaN? Can you please provide sample values for your Fields!ShipmentPercentage. Value that causes a NaN?
As mentioned by @itcouple, SUM expects numeric data. NaN means "Not a Number".
As mentioned by @itcouple, SUM expects numeric data. NaN means "Not a Number".
ASKER
Not sure if this is waht your asking for but, 111010.xls
OK. Try the following:
=Sum(CDec(IIF(IsNumeric(Tr im(Replace (Fields!Sh ipmentPerc entage.Val ue,"%","") )), Trim(Replace(Fields!Shipme ntPercenta ge.Value," %","")) , 0.0 ) ))
=Sum(CDec(IIF(IsNumeric(Tr
ASKER
=Sum(CDec(IIF(IsNumeric(Tr im(Replace (Fields!Sh ipmentPerc entage.Val ue,"%","") )), Trim(Replace(Fields!Shipme ntPercenta ge.Value," %","")) , 0.0 ) ))
returned
Build complete -- 0 errors, 0 warnings
[rsRuntimeErrorInExpressio n] The Value expression for the textbox ‘textbox26’ contains an error: Conversion from string "NaN" to type 'Decimal' is not valid.
Preview complete -- 0 errors, 1 warnings
It is beautiful code though.. though it was going to work :o)
returned
Build complete -- 0 errors, 0 warnings
[rsRuntimeErrorInExpressio
Preview complete -- 0 errors, 1 warnings
It is beautiful code though.. though it was going to work :o)
OK. Take two.... :-)
=Sum(CDec(IIF(IsNumeric(Tr im(Replace (Replace(F ields!Ship mentPercen tage.Value ,"NaN","") ,"%",""))) , Trim(Replace(Replace(Field s!Shipment Percentage .Value,"Na N",""),"%" ,"")) , 0.0 ) ))
=Sum(CDec(IIF(IsNumeric(Tr
ASKER
Almost there but, I am get big numbers like 2323% with sum, I changed it to Avg then I got like 7% because of the zeros
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Also, try this one:
=Sum(CDbl(Fields!ShipmentP