473,396 Members | 1,703 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Weighted YTD Avg?

I have the following data
Month/Year Rep Avg Courtesy Rating Number Returned
--------------------------------------------------------
May 2005 BJM 3.6 2
June 2005 BJM 3.2 3

I want to have a YTD weighted average -

So in this case, here is how I would calculate that:

Sum(Avg Rating * Number Returned)
---------------------------------
Total Number Returned

3.6*2+3.2*3 / 5 = YTD Total of 3.36

How can this be done in a query or report?

Thanks
Brian

Nov 13 '05 #1
1 1895
Brian,

Try this, I'm sure there are others who are better at SQL who
can show you a better method.

1.Create Query1
SELECT Table1.tRep, Year([tDate]) AS tYear, Sum(([tRate]*[tReturns])) AS
Total
FROM Table1 GROUP BY Table1.tRep, Year([tDate]);

This will give you the year extracted from the date so you can group be
rep id
and year. Also it calculates the sum of rate * returns which will be by
rep id and year.
2. Create Query2
SELECT Table1.tRep, Year([tDate]) AS tYear, Sum(Table1.tReturns) AS
SumOftReturns
FROM Table1 GROUP BY Table1.tRep, Year([tDate]);

This gives you the total number of returns by rep id and year.

3. Create Query3
SELECT Query1.tRep, Query1.tYear, Query1.Total, [Total]/[SumOftReturns]
AS WtAvg
FROM Query1 INNER JOIN Query2 ON (Query1.tYear = Query2.tYear) AND
(Query1.tRep = Query2.tRep);

This will join Query1 and Query2 by rep id and year and calculate the Wt
Avg by
Total / SumOftReturns

BerkshireGuy wrote:
I have the following data
Month/Year Rep Avg Courtesy Rating Number Returned
--------------------------------------------------------
May 2005 BJM 3.6 2
June 2005 BJM 3.2 3

I want to have a YTD weighted average -

So in this case, here is how I would calculate that:

Sum(Avg Rating * Number Returned)
---------------------------------
Total Number Returned

3.6*2+3.2*3 / 5 = YTD Total of 3.36

How can this be done in a query or report?

Thanks
Brian


Nov 13 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Louis | last post by:
Hi, Does anyone know of a script that will give "weighted job duration"? I want to use it, to identify which jobs are hogging the CPU. That is for a given server, list the sql agent jobs...
0
by: Rolan | last post by:
I know what I want to do regarding the average cost for inventory, but need some assistance to sort out some of the details to finalize an inventory table and query. Essentially, the information is...
2
by: Jim | last post by:
Hi, Can someone sugest the best way to map one number to another. i.e. 110 becomes 99, 109 becomes 97 or somthing like 105 to 100 becomes 67. I have 20 values that I need to map in this manner and...
8
by: DQ dont quit | last post by:
I'm currently working on a ASP.Net / C# / SQL 2000 project that involves the entering of keywords, that a web user enters, and then searching MSWord documents for those words. This information...
3
by: Michael McGarry | last post by:
Hi, I am looking for a weighted bipartite matching implementation in C, does anyone know where I can find one? Thanks, Michael
1
by: HEMH6 | last post by:
Weihted Average Write a C program to calculate and print the weighted average of a list of N floating point number, using the formula Xave = F1X1 + F2X2+...+ FnXn where the F's are...
3
by: Salad | last post by:
http://www.mathwords.com/w/weighted_average.htm At the above link gives an example of a weighted average. It uses the following example: Grades are often computed using a weighted average....
6
by: alessandro.carrega | last post by:
In Igraph library (http://cneurocvs.rmki.kfki.hu/igraph/) there's a method to add a weighted edge?
0
by: edmund_xue | last post by:
Hello There, I was just working on a project of creating a database for a relative that have alots of clients. His company managed the shares portfolio of clients and he requires the buy price...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.