Great, this works!
Thank you Gary and Steve for your help!
BR,
Petteri Toukoniitty
Hi Petteri,
I might assume you have a lot of data and your table has a pk like "ID" in
tblResponse below.
tblResponseIDRespDateRespTime
15/1/20053
25/1/20056
35/2/20054
45/3/20052
55/4/20054
65/6/20053
75/7/20058
85/8/20055
95/9/20055
105/10/20053
115/11/20052
125/12/20054
135/13/20051
145/14/20058
155/15/20054
165/16/20053
175/17/20056
185/18/20057
195/19/20057
205/20/20054
216/1/20053
226/1/20055
236/2/20053
246/3/20056
256/4/20059
266/6/20052
276/7/20054
286/8/20055
296/9/20057
306/10/20053
316/11/20051
326/12/20054
336/13/20056
346/14/20053
356/15/20057
366/16/20054
376/17/20054
386/18/20052
396/19/20057
406/20/20055
416/21/20055
426/22/20053
436/23/20059
446/24/20054
456/25/20056
I also might assume that you want
to show your results in a report.
If the above is true, then while the
following probably can be achieved in a
Steve-Dassin-like crosstab, it might
help to break the process down into
query steps.
The gist of this method is to rank
the times within a year/month group.
Then you can use this rank to give each
time a "rank %", i.e., Rank/Count of group.
You can then group on (RankPercent<=.9)
to get your 2 groups which you can apply
aggregates to.
I might suggest creating a scratch table
(say "tblScratch") with following fields:
RespYear Long
RespMonth Long
RespTime Long
ID Long
Rank Long
RankPerCent Single
When you start the process, clear tblScratch
of all records. Then run the following append qry:
INSERT INTO tblScratch ( RespYear, RespMonth, RespTime, ID, Rank )
SELECT
Year([RespDate]) AS RespYear,
Month([RespDate]) AS RespMonth,
t1.RespTime,
t1.ID,
(SELECT COUNT(*) FROM tblResponse t2
WHERE
Year(t2.RespDate)=Year(t1.RespDate)
AND
Month(t2.RespDate)=Month(t1.RespDate)
AND
t2.RespTime*1000+t2.ID*.001 < t1.RespTime*1000+t1.ID*.001)+1 AS Rank
FROM tblResponse AS t1
ORDER BY
Year([RespDate]),
Month([RespDate]),
t1.RespTime,
t1.ID;
then run the following update qry:
UPDATE tblScratch AS S
SET S.RankPerCent =
.[Rank]/DCount("*","tblScratch","[RespYear]=" &
.[RespYear] & " AND [RespMonth]=" & .[RespMonth]);
with above data, your tblScratch would now look like:
tblScratchRespYearRespMonthRespTimeIDRankRankPerCent
2005511310.05
200552420.1
2005521130.15
200553140.2
200553650.25
2005531060.3
2005531670.35
200554380.4
200554590.45
20055412100.5
20055415110.55
20055420120.6
2005558130.65
2005559140.7
2005562150.75
20055617160.8
20055718170.85
20055719180.9
2005587190.95
20055814201
2005613110.04
2005622620.08
2005623830.12
2005632140.16
2005632350.2
2005633060.24
2005633470.28
2005634280.32
2005642790.36
20056432100.4
20056436110.44
20056437120.48
20056444130.52
20056522140.56
20056528150.6
20056540160.64
20056541170.68
20056624180.72
20056633190.76
20056645200.8
20056729210.84
20056735220.88
20056739230.92
20056925240.96
20056943251
From here, you could go several ways.
One way would be to base your report on the
following query:
SELECT
S.RespYear,
S.RespMonth,
Count(S.RespTime) AS Cnt,
Min(S.RespTime) AS MinRespTime,
Max(S.RespTime) AS MaxRespTime,
Avg(S.RespTime) AS AvgRespTime,
[RankPerCent]<=0.9 AS InTop90
FROM tblScratch AS S
GROUP BY
S.RespYear,
S.RespMonth,
[RankPerCent]<=0.9;
qryrptResponseTimeRespYearRespMonthCntMinRespTimeMaxRespTimeAvgRespTimeInTop
90
2005518174.05555555555556-1
2005528880
2005622174.18181818181818-1
200563798.333333333333330
Petteri Toukoniitty said:
Hi Steve,
and thank you for your answer!
I'm still having some problems with the query. I know how to use the average
function, but the problem is that it can't be
used directly in this case as it would calculate average amount for each
month.
What I need is that the query should
1) Take 90% of the fastest response times per month (e.g. sort the response
times for each month, then take top-90% of these per month)
2) Calculate average for these top 90% response times per month
3) Calculate average for the remaining 10%
So this way each month would have two averages, one for the faster reponse
times and one for the slower ones.
So my guess is that I should somehow combine the average-function and the
"SELECT TOP 90 PERCENT" attribute in access/SQL,
but I don't know how... Does anyone have clue how to do this?
Cheers,
Petteri
[MVP] S.Clark said:
I'll admit that I don't totally understand, but you can use the Average
operator in a query.
SELECT [ID], Average([Field]) FROM [Tablename] GROUP BY [ID]
You can also make a crosstab query to transpose data to be a column.
Using the two together, probably in two or more queries, you can get to
where you want to go.
--
Steve Clark, Access MVP
FMS, Inc.
www.fmsinc.com/consulting
Hi,
I have a database containing info about response times to user
requests. In addition to the response time, each record contains date
when the request was made. Now I need to count two averages for each
month: average for top 90% of the response times (ordered by response
time to get the top 90%) and other average for the remaining 10%.
Example table:
Date(month) Response time (minutes)
January 1
January 2
January 5
January 4
February 8
February 2
The query should then return something like this:
Date(month) Avg top 90% Avg remaining
January X Y
February X2 Y2
Where X would be the average response time for the fastest 90% of the
response times, and Y would be the average for the remaining requests
that have the longest response times.
How could I do this with Access?
Thanks in advance,
Petteri