Calculate average for the those who meet a certain criteria - reporting-services

I'm trying to calculate the average for only particular records
For example, we have a field called FurthestSlide. This field will contain numbers. We have another field called SlideCount. This is also a number field.
I only want it to calculate the average for the records where the FurthestSlide does not equal the SlideCount number.
What I am trying to find is the average FurthestSlide number for those people who did not view the entire message.
I do not want those who finished the message to be calculated in the data.
Sample Data:
SlideCount=40
FurthestSlide=(30,20,40,40,40)
The answer should come out to 25. (30+20)/2

You can exclude certain rows from an aggregate.
With your data:
And a simple report:
I have calculated the average for non-matching rows with the expression:
=Avg(IIf(Fields!FurthestSlide.Value <> Fields!SlideCount.Value
, Fields!FurthestSlide.Value
, Nothing))
Here we set matched rows FurthestSlide value as Nothing, which means they are excluded from any average calculation.
This gives the required result for your data:

Related

SSRS 2016 - How to calculate a percentage difference between two values in a group?

I'm creating a report that shows the sales of item before a date range and after a date range.
The part I ran into trouble with is the percentage difference between the total sales on Date 1 and Date 2.
Items can have no sales for a certain week.
The user can select multiple item ID's in the item ID parameter.
I can update the question to post my SQL query if needed.
What I've tried
Since I put a group on item ID I thought the First and Last functions would work.
Here's my expression on the column PCT.
=(Last(Fields!total_sales1.Value, "Date1")- First(Fields!total_sales1.Value, "Date1")) / First(Fields!total_sales1.Value, "Date1") * 100
But when I run the report I get the following results.
I need an expression on PCT column that will give me a percentage difference for each item pairs.
It looks like your scope is incorrect. Check what the rowgroup is called where you group by item id (let's say the row group is called "yourItemRowGroupName").
Then change you expression to use that scope rather than "Date1".
In fact you may not need the scope at all as it should work within the scope that expression sits (in your case, within your ItemID group.).
So try
=(Last(Fields!total_sales1.Value)- First(Fields!total_sales1.Value)) / First(Fields!total_sales1.Value) * 100
Or..
=(Last(Fields!total_sales1.Value, "yourItemRowGroupName")- First(Fields!total_sales1.Value, "yourItemRowGroupName")) / First(Fields!total_sales1.Value, "yourItemRowGroupName") * 100
You may have to handle divide by zero but try this to start with before you add any more complications.

mysql - calculating columns(2 columns with numbers) based on another group of column(text)

Hi I would like to find a query for the below, I am trying to calculate data between two columns however based on another column which needs to be a selected group of the same values
Unfiltered
Start Time________Disconnect Time______Signalling IP
12:59:00.3________13:26:03.3___________1.1.1.1
10:59:00.3________11:03:03.3___________2.2.2.2
19:59:00.3________20:02:03.3___________1.1.1.1
Filtered
Start Time________Disconnect Time______Signalling IP
12:59:00.3________13:26:03.3___________1.1.1.1
19:59:00.3________20:02:03.3___________1.1.1.1
If you see the table above, I want the selected IP only which is 1.1.1.1, and then from there, calculate the total duration of time from the Start Time and Disconnect Time for that Egress IP.
So column 3 has multiple values, however I need to select the same value, then from there calculate the sum of column 1 and 2 based on column 3.
Please let me know if you have anything in mind, as I have tried multiple queries but can't get the correct one
to calculate difference between to times.
you can use time_to_sec to convert each time value to seconds
and subtract start time from end time to get time period in seconds.
you cat turn it back to time format with SEC_TO_TIME
example
select
column3,
SEC_TO_TIME(sum(TIME_TO_SEC(column2) - TIME_TO_SEC(column1))
from
table
group by column3

spotfire multiple over statements in one custom expression

I have a table of travel expenses for analysis.
I would like to create a calculated column with a value for the maximum count of records with a certain category for each employee on any given day.
For example, if the category being reviewed is "dinner", we would like to know what is the maximum number of dinner transactions charged on any given day.
The following custom expression was able to count how many dinner expenses per employee:
count(If([Expense Type]="Dinner",[Expense Type],null)) over ([Employee])
But when trying to get the max count over days, I cant seem to get it to work. Here is the expression used:
Max(count(If([Expense Type]="Dinner",[Expense Type],null)) over ([Employee])) over (Intersect([Employee],[Transaction Date]))
This seems to provide the same answer as the first expression. Any idea on how to get this code to identify the value on the date with the most expenses for each employee?
If i understand your question and comments correctly, you should be able to use intersect.
count(If([Expense Type]="Dinner",[Expense Type],null)) over (Intersect([Transaction Date],[Employee]))
You may need to cast [Transaction Date] as a date if it is an actual DateTime. Otherwise you'd get one for each unique DT.

Get number of entries grouped by X points in time in MySQL

I need to build the backend for a chart, which needs to have a fixed amount of data points, let's assume 10 for this example. I need to get all entries in a table, have them split into 10 chunks (by their respective date column) and show how many entries there were between each date interval.
I have managed to do kind of the opposite (I can get the entries for a fixed interval, and variable number of data points), but now I need a fixed number of data points and variable date interval.
What I was thinking (which didn't work) is to get the difference between the min and max date from the table, divide it by 10 (number of data points) and have each row's date column divided by that result and also grouped by it. I either screwed up the query somewhere or my logic is faulty, because it didn't work.
Something along these lines:
SELECT (UNIX_TIMESTAMP(created_at) DIV (SELECT (MAX(UNIX_TIMESTAMP(created_at)) - MIN(UNIX_TIMESTAMP(created_at))) / 10 FROM user)) x FROM user GROUP BY x;

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.