SSRS: Summing Static Rows Defined by Expressions - reporting-services

I am building a report that looks like:
Last 30 Days Last 60 Days Last 90 Days
SLA Met* 1 3 5
SLA Missed* 2 4 6
Total 3 7 11
The datasource is via FetchXML and only one dataset is being used for the table. I am calculating the static rows, SLA Met and SLA Missed, using the expresion:
=(Count(IIf Condition, 1, Nothing)).
Any ideas how I would get the total of these two static rows, as they do not belong to a group, not fields that I can easily sum, and are defined by an expression?
Thanks.

If I clearly understood the problem, the solution would be simple: = (expression) + (expression)
This amount must be in the same table.

You can create calculated fields with your condition, then use that data to create your total rows. They would then belong to the group and would be easy to sum up.

Related

Is it possible to limit RunningValue to look back for a certain number of rows?

Im trying to average the past 5 rows in my table i created in SSRS grouped by date(Monday of every week). Ive tried runningValue however it looks back at all the past rows for each group. Is there a way to limit the scope to just the past 5 rows or weeks for each Date group.
Thanks
I would accomplish this with grouping. I don't know what your dataset is like but I assume it is a SQL query you can modify. The easiest solution would be to add a week number column to your query. For example:
SELECT datepart(week, YOURDATE) as WeekNumber
More info on datepart:
https://learn.microsoft.com/en-us/sql/t-sql/functions/datepart-transact-sql?view=sql-server-2017
Once you have a week number, use the table creation wizard in Report Builder and add WeekNumber as a row group. This will group your values by week number and give you a total under each week. You can change the total by double clicking and making it AVG() instead of SUM().
Note: If you already have each 5 day period in a group, you should be able to right click that and add total. At which point you can just change the SUM to AVG there.

MySQL - SUM() old entries

I've a table with lots of entries consisting of dates and a number.
For instance:
07.02.2016 - 12
06.02.2016 - 48
05.02.2015 - 24
...and so on.
Now I need to sum all of the values older than 2 months. For instance the 3rd entry (05.02.2015) will be added to the second (06.02.2016) and the second one should get the value 72 and the 3rd one should be deleted.
I'd like to know if there is some way to do this in mysql only?
Instead of writing the code for you, I'd like to merely give you some hints:
Identify which rows are older than 2 month and sum them up.
select sum(number) from table where date > curdate() + interval 2 months
or sth. similar will do.
Select the max. date of the entries that are smaller or equal to "now+2months".
Update that row with the value from step 1.
Delete the rows from step 1.
See here for details on date functions in MySQL.
This can be done in 2 statements (one for steps 1-3, one for the deletion).

sum of last field

I have a trouble to sum fields.
This is what I have: I have list of employees and two rows of values for each, I also have calculations in SQL of running total for the 8 and 16 weeks for each employee for each of two rows using windowing function. I have to group employees by branches they work and calculate sum of running totals for the last 8 and 16 weeks for each row and then device row 1 by row 2. I need to use Last function, because I only need the running total for the last 8 and 16 weeks. The challenge is to go around and have something like: Sum(Last(Fields!Last116WeekSilk.Value) . this one obviously gives me an error. I have tried to add calculated field to the dataset with both Sum and Last functions, doesn’t work, tried RunningValue, doesn’t work. What else can I do to have the sum of last running totals?
Many thanks in advance
I would add the SQL ROW_NUMBER function to the query and derive the row number (e.g. 1 or 2) within each group. If you do this in descending sequence the row number 1 will always be the last row within the group.
Then in SSRS you can use an Iif to only show/calculate on row number 1.

subtract the data for every 5 minutes between two particular times

I have some problem with MYSQL,I need to subtract the data between two particular times,for every 5 minutes and then average it the 5 minutes data.
What I am doing now is:
select (avg(columnname)),convert((min(datetime) div 500)*500, datetime) + INTERVAL 5 minute as endOfInterval
from Databasename.Tablename
where datetime BETWEEN '2012-09-12 10:50:00' AND '2012-09-12 14:50:00'
group by datetime div 500;
It is the cumulative average.
Suppose i get 500 at 11 o' clock and 700 at 11.05 ,the average i need is (700-500)/5 = 40.
But now i am getting (500+700)/5 = 240.
I dont need the cumulative average .
Kindly help me.
For the kind of average you're talking about, you don't want to aggregate multiple rows using a GROUP BY clause. INstead, you want to compute your result using exactly two diffrent rows from the same table. This calls for a self-join:
SELECT (b.columnname - a.columnname)/5, a.datetime, b.datetime
FROM Database.Tablename a, Database.Tablename b
WHERE b.datetime = a.datetime + INTERVAL 5 MINUTE
AND a.datetime BETWEEN '2012-09-12 10:50:00' AND '2012-09-12 14:45:00'
a and b refer to two different rows of the same table. The WHERE clause ensures that they are exactly 5 minutes apart.
If there is no second column matching that temporal distance, no resulting row will be included in the query result. If your table doesn't have data points exactly every five minutes, but you have to search for the suitable partner instead, then things become much more difficult. This answer might perhaps be adjusted for that use case. Or you might implement this at the application level, instead of on the database server.

Returning rows of aggregate results from single SQL query

I have a MySQL table containing a column to store time and another to store a value associated with that time.
time | value
------------
1 | 0.5
3 | 1.0
4 | 1.5
.... | .....
The events are not periodic, i.e., the time values do not increment by fix interval.
As there are large number of rows (> 100000), for the purpose of showing the values in a graph I would like to be able to aggregate (mean) the values for an interval of fixed size over the entire length of time for which the data is available. So basically the output should consist of pairs of interval and mean values.
Currently, I am splitting the total time interval into fixed chunks of time, executing individual aggregate queries for that interval and collecting the results in application code (Java). Is there a way to do all of these steps in SQL. Also, I am currently using MySQL but am open to other databases that might support an efficient solution.
SELECT FLOOR(time / x) AS Inter, AVG(value) AS Mean
FROM `table`
GROUP BY Inter;
Where x is your interval of fixed size.
I've usually solved this through a "period" table, with all the valid times in it, and an association with the period on which I report.
For instance:
time day week month year
1 1 1 1 2001
2 1 1 1 2001
....
999 7 52 12 2010
You can then join your time to the "period" table time, and use AVG.