Complex SSRS expression (Average of Average) - reporting-services

I have 4 datasets and I need to calculate the average of a field and their cumulative average.
Here are my 4 datasets : Dataset1,Dataset2,Dataset3,Dataset4:
This what I want . I want to find the average of the average values as given below :
Avg(Fields!Discount.Value,"Dataset1")
Avg(Fields!Discount.Value,"Dataset2")
Avg(Fields!Discount.Value,"Dataset3")
Avg(Fields!Discount.Value,"Dataset4")
A logic of = Avg(Avg,Avg,Avg..) throws an error. So basically it doesn't work. There's gotta be a way surely ?
We need to also take into account that sometimes one of the datasets may be empty ( null or 0 ). Is there any way of doing it in SSRS ?

If you don't need a weighted average you can use ISNOTHING to check for the NULLs like:
=(IIF(ISNOTHING(Avg(Fields!Discount.Value,"Dataset1")), 0, Avg(Fields!Discount.Value,"Dataset1") ) +
IIF(ISNOTHING(Avg(Fields!Discount.Value,"Dataset2")), 0, Avg(Fields!Discount.Value,"Dataset2") ) +
IIF(ISNOTHING(Avg(Fields!Discount.Value,"Dataset3")), 0, Avg(Fields!Discount.Value,"Dataset3") ) +
IIF(ISNOTHING(Avg(Fields!Discount.Value,"Dataset4")), 0, Avg(Fields!Discount.Value,"Dataset4") ) ) / 4

Related

SSRS number of occurences for runningvalue

I'm trying to create the ABC / Pareto Analysis. Intention is to mark by 'A' all products which generate 80% of total sales, 'B' products which generate additional 15% and 'C' the rest. It's up to 100k products which have to be taken into account and fastest way to calculate running total is by using the RunningValue in the Report Builder / Paginated Reports.
I did some testing by calculating running total while downloading data to the dataset but it's very slow and therefore not an option. RunningValue on the other hand works perfectly fine and I can mark the products by 'A', 'B', and 'C' in the Tablix. This is the formula:
=IIF(RunningValue(Fields!ACT.Value, Sum, Nothing ) / Sum(Fields!ACT.Value, "Facts")<0.8, "A", IIF(RunningValue(Fields!ACT.Value, Sum, Nothing ) / Sum(Fields!ACT.Value, "Facts")<0.95,"B","C"))
However, I can't find a way how to count the number of products with A, B and C. Idea is to show that X% of products create 80% of total sales, Y% additional 15% and Z% generate only 5% of turnover.
I'd be thankful for any advice, I'm running out of options. Original datasource is Power BI dataset and calculating running total while downloading the data is really slow for this number of products. Tested with MDX and DAX.
You can use custom code for your pareto count calculation.
Add the following code to your report
Public Dim a_count, b_count, c_count As Integer
Public Function Pareto( current As Integer, total As Integer) As String
If current / total < 0.8 Then
a_count = a_count + 1
Return "A"
ElseIf current / total < 0.95 Then
b_count = b_count + 1
Return "B"
Else
c_count = c_count + 1
Return "C"
End If
End Function
For your parent classification column use the expression
= Code.Pareto( RunningValue(Fields!ACT.Value, Sum, Nothing ) , Sum(Fields!ACT.Value, "Facts"))
To display the counter variables use the expressions
= Code.a_count
= Code.b_count
= Code.c_count

Get value between from to dataset columns ssrs

I have a data set like that:
Data Set Contents
From To Comment
----+---+--------
0 50 Bad
50 70 Good
70 100 Excellent
If I have a value of 75, I need to get Excellent by searching the Dataset.
I know about the lookup function but it is not what I want. How can I do that?
The values should be in percentage.
Note : the value (75) is Average of a column (Calculated) it
calculate student grade from max and student mark Version SQL Server
2016
Note 2 : the dataset is from database not static values
Thank You
Assuming you only ever have a fixed number of 'grades' then this will work. However, I would strongly recommend doing this type of work on the server where possible.
Here we go...
I created two datasets
dsGradeRange with the following sql to recreate your example (more or less)
DECLARE #t TABLE (low int, high int, comment varchar(20))
INSERT INTO #t VALUES
(0,49,'Bad'),
(50,69,'Good'),
(70,100, 'Excellent')
SELECT * FROM #t
dsRandomNumbers This just creates 30 random numbers between 0 and 100
SELECT *
FROM (SELECT top 30 ABS(CHECKSUM(NEWID()) % 100) as myNumber FROM sys.objects) x
ORDER BY myNumber
I added a table to the report to show the grades (just for reference).
I then added a table to show the dsRandomNumbers
Finally I set the expression of the 2nd column to the following expression.
=SWITCH
(
Fields!myNumber.Value < LOOKUP("Bad", Fields!comment.Value, Fields!high.Value, "dsGradeRange"), "Bad",
Fields!myNumber.Value < LOOKUP("Good", Fields!comment.Value, Fields!high.Value, "dsGradeRange"), "Good",
True, "Excellent"
)
This gives the following results
As you can see we only need to compare to the high value of each case, the first match will return the correct comment.
Right click on your dataset and add a calculated field. Go to Field Properties > Fields > Add and add the following expression, which descripes your scenario:
=IIF(Fields!Number.Value < 50, "Bad", "Good")

IIF THEN in MDX for handling ∞ values

I am getting an
∞
value in my calculated measures.
I want to handle this value, & if it comes, it should display 0.
What I tried is,
1. IIF([Meaures].[Plant Share] = "∞" , 0, [Meaures].[Plant Share])
2. IIF([Meaures].[Plant Share] = "Infinity" , 0, [Meaures].[Plant Share])
Both seems not working.
In query output, I am getting ∞ as Infinity.
Any Idea how should I ?
Thanks.
Bytheway, to type ∞,
Windows ALT + 2 3 6
Macintosh Inser --> Symbol -> ∞
UPDATE:
This way I calculate the member.
WITH
MEMBER [Meaures].[Plant Share] AS(
([Meaures].[YTD Plant Share] / [Meaures].[PY YTD Plant Share] - 1 ) * 100
)
Change your measure to the following:
WITH
MEMBER [Meaures].[Plant Share] AS(
iif
([Meaures].[PY YTD Plant Share] = 0,
null,
([Meaures].[YTD Plant Share] / [Meaures].[PY YTD Plant Share] - 1 ) * 100
)
)
Awesome trick I found for this situation.
Simply use Divide function, newly introduced.
Divide (<numerator>, <denominator> [,<alternateresult>])
For more details, refer here.

Unable to do sum and division in mysql

Here is my mysql query
SELECT IntervalStartTime,IFNULL(SUM(AbandonedCalls),0) AS AbandonedCallSum,SUM(QueueTime) AS QTS,SUM(RingTime) AS RTS,
IFNULL(SUM(AnsweredCalls),0) AS AnsweredCallSum
FROM intervalqueuestatistics
WHERE CallCenterId=17 AND DATE_FORMAT(IntervalStartTime,'%m')=10 AND DATE_FORMAT(IntervalStartTime,'%Y')=2012
GROUP BY DATE_FORMAT(IntervalStartTime,'%d');
Now i want to calculate a value (SUM(QueueTime)+SUM(RingTime))/SUM(AnsweredCalls)
So i modified my query accordingly as below
SELECT IntervalStartTime,IFNULL(SUM(AbandonedCalls),0) AS AbandonedCallSum,SUM(QueueTime) AS QTS,SUM(RingTime) AS RTS,
IFNULL(SUM(AnsweredCalls),0) AS AnsweredCallSum,IFNULL(SUM(QueueTime),0) + IFNULL(SUM(RingTime),0)/IFNULL(SUM(AnsweredCalls),0)
FROM intervalqueuestatistics
WHERE CallCenterId=17 AND DATE_FORMAT(IntervalStartTime,'%m')=10 AND DATE_FORMAT(IntervalStartTime,'%Y')=2012
GROUP BY DATE_FORMAT(IntervalStartTime,'%d');
But when executed it isn't giving me the correct answer.
For example one of the rows returned by this query
QTS RTS AnsweredCallSum CalculatedField
188000 41645 9 192627.222
But the CalculatedField is wrong it should be 25516.11 as per the calculation mentioned above
If SUM(AnsweredCalls) is 0, you are dividing by 0 and it should not work.
This would be my guess:
use IFNULL(..., 1) so you're never dividing by 0 should a null column exist.
Explicitly use parenthesis so order of operations doesn't fail. (You're currently performing sum1 + (sum2 / sum3) when I think you wanted (sum1 + sum2) / sum3). Remember multiplication & division come before addition & subtraction without the parenthesis.
( IFNULL(SUM(QueueTime), 0) + IFNULL(SUM(RingTime), 0) )
/ IFNULL(SUM(AnsweredCalls), 1)

Microsoft Access - grand total adding multiple fields together

I can't quite figure this out. Microsoft Access 2000, on the report total section I have totals for three columns that are just numbers. These =Sum[(ThisColumn1)], 2, 3, etc and those grand totls all work fine.
I want to have another column that says =Sum([ThisColumn1])+Sum([ThisColumn2]) + Sum([ThisColumn3]) but can't figure those one out. Just get a blank so I am sure there is an error.
Give the 3 Grand Totals meaningful Control Names and then for the Grand Grand Total use:
=[GrandTotal1] + [GrandTotal2] + [GrandTotal3]
Your Grand Total formulas should be something like:
=Sum(Nz([ThisColumn1], 0))
NULL values propagate through an expression which means that if any of your three subtotals are blank, the final total will also be blank. For example:
NULL + 10 = NULL
Access has a built in function that you can use to convert NULL values to zero.
NZ( FieldName, ValueIfNull )
You can use NZ in reports, queries, forms and VBA.
So the example above could read like this:
=NZ([GrandTotal1],0) + NZ([GrandTotal2],0) + NZ([GrandTotal3],0)
http://office.microsoft.com/en-us/access/HA012288901033.aspx
Create a new query, and the sql should look like this:
SELECT SUM(Column1 + Column2 + Column3),
SUM(Column1),
SUM(Column2),
SUM(Column3),
FROM Your_Table;