AVG of SSRS Report Column - reporting-services

Using the function below to calculate the average of a column with numeric and text values, e.g. 3, 2.6, N/A
AVG(CInt(iif(IsNumeric(Fields!Score.Value)=True,Fields!Score.Value,"0")))
How do I calculate the average of numeric values only i.e. not sum and count text values?

As you probably realised, you are including 0 for each instance where the value is not numeric. So if you have 10 values, and 3 are not numeric you are still dividing the total by 10. I can't test this at the moment but try these options.
Change the "0" to nothing (no quotes).
Work out the average the old fashioned way ! with
SUM(CInt(iif(IsNumeric(Fields!Score.Value)=True,Fields!Score.Value,0))) / SUM(CInt(iif(IsNumeric(Fields!Score.Value)=True,1,0)))

Related

How to get sum of last 6 months depending on a parameter?

i'm currently working on a ssrs report. The report contains 4 parameters, only two are relevant to the question: no. 3 and no. 4. The label of parameter no. 3 are "12 periods" up to "24 periods", but the values are 12 up to 24 as integer.
This is what the report looks like:
enter image description here
For example if i choose the value "13 periods" (or higher) for parameter no. 3, the query retrieves data for 13 periods (or higher) startet with the last month depending on parameter no. 4. So the data are included the report. Now the column "Sum Consumtion" should be only store the Sum of the last 12 periods regardless of the parameter value no. 3 not 13 periods (or higher). So the Result is 67 not 77.
Any idea how can i do this?
Thx for your support...
You can do this by using a calculated field.
Add a calculated field to your dataset. The expression would filter it to the past 12 months. So it would be something like this:
=IIf(Fields!DateColumn.Value >= DateAdd(DateInterval.Months, -12, Parameters!EndDate.Value), Fields!ColumnToSum.Value, Nothing)
Now you can reference this new field in the total column. You would simply Sum it.
Depending on your date formats, you'll probably need to adjust the date comparison logic to meet your needs. If you don't have the End Date available in the report, add that first. It can be in the query or another calculated field in the report. But the idea is that you are getting a conditional sum.

Laravel Integer to Float or Decimal MySQL Column

I have a current db table called scores that has 2 columns user_score and approved_score which are both Integer.
After initial launch we have decided to make things more exact by add a decimal to a score. So instead of getting a 10 you could get a 10.40 or a 10.47 ect. I am just curious on:
Should I change it to a decimal or a float based on us needing 2
decimal points with trailing 0. So: $table-> decimal('user_score', 8,
2)->change();
Will that mess up data in there already? Like will a
score of 123 stay 123? We rank based on score so the higher the
better.
A float would be more appropriate in this case, it doesn't sound like you need a high number of precision points after the decimal place. The data should not be impacted by changing the column type, so long as your values are not currently larger than (8,2).
Also, updating your existing data if you kept the column as an integer would be trivial as all you would need to do is UPDATE column SET column=column*100.

SSRS Expression how to compare value from two different datasets?

So I've searched for this specifically but cannot find an example or answer anywhere.
I'm trying to compare a value of one dataset to the value of another dataset but it's not working.
Here's my expression:
=IIF((Fields!IC_ADV.Value + Fields!OC_ADV.Value) > 0, Max(Fields!AMOUNT.Value, "Data_bucket_info") > 15, nothing)
All I get is "True". If I remove the '> 15' then I get a value but it's not the right value. I've tried replacing Max with First, Min, Sum; without the '>15' I again get a value but not the right one and with the '>15' I get "True" or "False".
If I have Max in, I'm expecting to get the Max value for AMOUNT for all amount > 15; if I have Min in, I'm expecting to get the Min value for AMOUNT for all amount > 15.
So for example:
AMOUNT is in increments of 5; so 5, 10, 15, 20, 25....etc.
If (Fields!IC_ADV.Value + Fields!OC_ADV.Value) = 24 then what I want is for AMOUNT to display 25. If (Fields!IC_ADV.Value + Fields!OC_ADV.Value) = 3 then I want AMOUNT to display 5.
The warning I keep getting in SSRS is 'The Value expression for the textrun 'Textbox12.Paragraphs[0].TextRuns[0]' uses a numeric aggregate function on data that is not numeric. Numeric aggregate functions (Sum, Avg, StDev, Var, StDevP, and VarP) can only aggregate numeric data.'
But the AMOUNT field is a numeric value.
It is not lot clear from your description what you are trying to achieve. But for what I understand you want to match the sum of IC_ADV and OC_ADV with some value and depending on that you want to get the value. for that you can set the expression as below,
=IIF((Fields!IC_ADV.Value + Fields!OC_ADV.Value) = 24,Max(Fields!AMOUNT.Value, "Data_bucket_info"),IIF((Fields!IC_ADV.Value + Fields!OC_ADV.Value) = 3,Min(Fields!AMOUNT.Value, "Data_bucket_info"),Nothing)
But if you want to match match value of one dataset to another datasets value based on some common field then you should take a look at the LookUp. Here is more info.
In this scenario, I think it's better to make it in Math way. Try the expression below:
=((Fields!IC_ADV.Value + Fields!OC_ADV.Value)\5+1)*5

Average of all values Except 0

I have a report that I have designed in SSRS 2008. I have a row which has couple of values. This is basically a Survey form where there are Values from 1 to 5 .Some of the values are either Blank or N/A(If they don't answer). But While I calculate Average of the Values it includes that particular value. I think it takes it as 0. So
Average of (4, 5,4,4,5,2,3, ,5) = 3.56 instead of 4.00.
Can You please tell me how I can Calculate Average of the the values without considering Blank values.
Thank you
You can add a calculated field to your dataset to filter out the unwanted values. Then you can just use a regular expression to make it more readable. Here's an example of the calculated field expression:
=iif(Fields!Score.Value > 0, Fields!Score.Value, Nothing)
Now you can simply reference =Avg(Fields!FilteredScore.Value) and it will work as desired.
I found the below solution for solving my problem:
=SUM(Fields!Score.Value)/Sum(iif(Fields!Score<>0,1,0))
Instead of using inbuilt average function, you need to create your own function to accomplish your task.
Mathematically Average = (sum of all answers)/(count of all answers)
For your case you need to modify the denomination to exclude all blank and N/A values.
New Avg func = (sum of all answers)/((count of all answers)-(count of all answers where it is blank or N/A))
SSRS equivalent:
=SUM(Fields!SurveyAnswer.Value)/
(Count(Fields!SurveyAnswer.Value)-
Count(IIF(Fields!SurveyAnswer="" OR UCASE(Fields!SurveyAnswer)="N/A", 1, **NOTHING**)))
OR
=SUM(Fields!SurveyAnswer.Value)/(Count(Fields!SurveyAnswer.Value)-
SUM(IIF(Fields!SurveyAnswer="" OR UCASE(Fields!SurveyAnswer)="N/A", 1, 0)))
HTH.

SSRS Conditional Summing

I have an SSRS report that displays several pages of rows. In each row is a "TYPE" field. In that TYPE field there is either an "M" for the value or a "P" for the value. At the end of the report I want to summ up all the price values for the "P" TYPES. I tried this but it prioduced an #Error:
=Sum(iif(Fields!TYPE.Value = "P",Fields!EXT_QTY.Value * Fields!PRICE.Value ,0))
this summed all rows
=iif(Fields!PART_TYPE.Value = "P" , Sum(Fields!EXT_QTY.Value * Fields!PRICE.Value ), 0 )
I'm sure this is do-able. Any ideas? Thanks
Found the answer....
=SUM(IIF(Fields!PART_TYPE.Value ="P",CDbl(Fields!EXT_QTY.Value * Fields!PRICE.Value), CDbl(0.0)))
The SUM fails due to type comparison - you can't Sum values of different types, being the expression (probably a Double) with 0, an Integer. MikeTWebb's answer does explicit type conversion to get around this error. This is fine for this specific example, being a Sum, however this doesn't produce an accurate result if you want an average (being Sum / Count) of the values where the Type is P. That is because 0 is a value and would be included in the averaging calculation when you actually want those values excluded from the calculation.
Another option is to use Nothing instead of 0:
=Sum(IIF(Fields!TYPE.Value = "P", Fields!EXT_QTY.Value * Fields!PRICE.Value, Nothing))
This solves the type comparison error without needing explicit typecasting and is a better solution when you are using aggregations where whether the value exists or not is significant to the result, like Average.