473,848 Members | 1,788 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Cumulative variance

I am pulling my hair out trying to solve this one (presumably because
I am not particularly trained or skilled at access!)

I have a query which summarises the variances that each of my sales
guys have created from their targets. This summarises by week, and
works fine. I then re-use this into a cross-tab which presents a nice
orderly table.

My boss would like to see these variances accumulate, so that we could
make a nice graph in Excel of who is doing well against the baseline
target, and who isn't.

I can't seem to find a way of creating a running total of the
variances that are being created.

e.g

Rep_ID Week No Variance Cumulative
1 1 0.01 0.01
1 2 -0.03 -0.02
1 3 0.01 -0.01
etc etc

I've seen some discussion of Dsum as the tool for this, but I think I
may be missing something......

Any pointers gratefully received!

Matt
UK
Nov 12 '05 #1
4 6498
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

You've got a problem. Usually, a running (cumulative) total can be
calculated in a query this way:

SELECT Rep_ID, WeekNo, SUM(RepSales) As SalesSum,

(SELECT SUM(RepSales)
FROM Sales
WHERE Rep_ID = S.Rep_ID AND WeekNo <= S.WeekNO ) As Cumulative

FROM Sales As S
WHERE ... < your criteria > ...
ORDER BY Rep_ID, WeekNo

The subquery in the SELECT clause will calc the running total for the
column RepSales for the query's "current" Rep_ID and WeekNo.

The trouble is you want something like this:

SELECT Rep_ID, WeekNo, VAR(RepSales) As Variance,

(SELECT SUM(VAR(RepSale s))
FROM Sales
WHERE Rep_ID = S.Rep_ID AND WeekNo <= S.WeekNO ) As Cumulative

FROM Sales As S
.... etc. ...

Which can't be done, because SQL doesn't allow an aggregate function
to have another aggregate function as part of it's expression (what's
inside the parentheses). So, you'll probably have to run 2 queries to
get the results:

qryVariance:

SELECT Rep_ID, WeekNo, VAR(RepSales) As Variance,
FROM Sales As S
WHERE ... < your criteria > ...
GROUP BY Rep_ID, WeekNo
qryVarianceRunn ingSum:

SELECT Rep_ID, WeekNo, Variance,

(SELECT SUM(Variance)
FROM qryVariance
WHERE Rep_ID = V.Rep_ID AND WeekNo <= V.WeekNO ) As Cumulative

FROM qryVariance AS V
ORDER BY Rep_ID, WeekNo

You can also substitute the DSum() function for the subquery:

DSum("Variance" , "qryVarianc e",
"Rep_ID=V.Rep_I D AND WeekNo <= V.WeekNO")

Not sure if this will work ('cuz of summing a variance column in
another query). If it doesn't you may want to save the results of
qryVariance to a temp. table and then change qryVarianceRunn ingSum to
this:

SELECT Rep_ID, WeekNo, Variance, SUM(Variance) As Cumulative
FROM tblVariance_tmp AS V
GROUP BY Rep_ID, WeekNo, Variance

I've found that using a subquery in the SELECT statement of a query
causes Access report's to reject the query, even though the query runs
from query design view! That's when using a domain aggregate function
(e.g.: DSum()) is needed.

- --
MGFoster:::mgf
Oakland, CA (USA)

-----BEGIN PGP SIGNATURE-----
Version: PGP for Personal Privacy 5.0
Charset: noconv

iQA/AwUBP6qwioechKq OuFEgEQJtRwCfV1 e1/ubXicEAWetPXZVB KwiQDLYAn1Ct
gstDlvVS8OF9AAp 7i9Y1+l9I
=ZftM
-----END PGP SIGNATURE-----
Matt Larkin wrote:
I am pulling my hair out trying to solve this one (presumably because
I am not particularly trained or skilled at access!)

I have a query which summarises the variances that each of my sales
guys have created from their targets. This summarises by week, and
works fine. I then re-use this into a cross-tab which presents a nice
orderly table.

My boss would like to see these variances accumulate, so that we could
make a nice graph in Excel of who is doing well against the baseline
target, and who isn't.

I can't seem to find a way of creating a running total of the
variances that are being created.

e.g

Rep_ID Week No Variance Cumulative
1 1 0.01 0.01
1 2 -0.03 -0.02
1 3 0.01 -0.01
etc etc

I've seen some discussion of Dsum as the tool for this, but I think I
may be missing something......

Any pointers gratefully received!

Matt
UK


Nov 12 '05 #2
Matt,
if your query was called qryVariances, and had columns called
Rep_ID, Week_Number and Variance then the following query will give a
running sum of the variance for each Rep:

SELECT T1.Rep_ID, T2.Week_Number, Sum(T1.Variance ) AS SumOfVariance
FROM qryVariances AS T1 INNER JOIN qryVariances AS T2 ON T1.Rep_ID =
T2.Rep_ID
WHERE (((T2.Week_Numb er)>=[T1].[Week_Number]))
GROUP BY T1.Rep_ID, T2.Week_Number
ORDER BY T1.Rep_ID, T2.Week_Number;

You could use the results of this query as the input for your crosstab
table. I recommend Celko's "SQL for Smarties" - where I got this
query type.

Good luck,
Martin

go************@ mattandsarah.or g.uk (Matt Larkin) wrote in message news:<91******* *************** **@posting.goog le.com>...
I am pulling my hair out trying to solve this one (presumably because
I am not particularly trained or skilled at access!)

I have a query which summarises the variances that each of my sales
guys have created from their targets. This summarises by week, and
works fine. I then re-use this into a cross-tab which presents a nice
orderly table.

My boss would like to see these variances accumulate, so that we could
make a nice graph in Excel of who is doing well against the baseline
target, and who isn't.

I can't seem to find a way of creating a running total of the
variances that are being created.

e.g

Rep_ID Week No Variance Cumulative
1 1 0.01 0.01
1 2 -0.03 -0.02
1 3 0.01 -0.01
etc etc

I've seen some discussion of Dsum as the tool for this, but I think I
may be missing something......

Any pointers gratefully received!

Matt
UK

Nov 12 '05 #3
Ma************* **@dsto.defence .gov.au (Iago Gallego) wrote in message news:<a5******* *************** ****@posting.go ogle.com>...
Matt,
if your query was called qryVariances, and had columns called
Rep_ID, Week_Number and Variance then the following query will give a
running sum of the variance for each Rep:

SELECT T1.Rep_ID, T2.Week_Number, Sum(T1.Variance ) AS SumOfVariance
FROM qryVariances AS T1 INNER JOIN qryVariances AS T2 ON T1.Rep_ID =
T2.Rep_ID
WHERE (((T2.Week_Numb er)>=[T1].[Week_Number]))
GROUP BY T1.Rep_ID, T2.Week_Number
ORDER BY T1.Rep_ID, T2.Week_Number;

You could use the results of this query as the input for your crosstab
table. I recommend Celko's "SQL for Smarties" - where I got this
query type.

Good luck,
Martin

Not sure if I understood this correctly - the references to T1 and T2
in particular.

The source for the qryVariances is a single table of Rep_ID,
Week_Number etc.

Do I need further reference tables (in the example above, T1, T2)
containing week and rep details?

TIA, much appreciated!

Matt
Nov 12 '05 #4
Matt,
it is confusing, yes. :)

The query I gave works with two copies of the same table/query. To
tell them apart, the FROM clause has the same table twice and gives
each instance an alias (T1 and T2 in this case). If you were to use
the QBE window, it would have the two tables joined on the Rep_Id
column, but no other joins.

If you want to add week and rep details, I would be tempted to add
them afterwards (in a query using the results of this one - but then I
tend to chain my queries. Its may not be efficient, but it fits my
"top-down" programming approach.

Best of luck,
Martin
go************@ mattandsarah.or g.uk (Matt Larkin) wrote in message news:<91******* *************** **@posting.goog le.com>...
Ma************* **@dsto.defence .gov.au (Iago Gallego) wrote in message news:<a5******* *************** ****@posting.go ogle.com>...
Matt,
if your query was called qryVariances, and had columns called
Rep_ID, Week_Number and Variance then the following query will give a
running sum of the variance for each Rep:

SELECT T1.Rep_ID, T2.Week_Number, Sum(T1.Variance ) AS SumOfVariance
FROM qryVariances AS T1 INNER JOIN qryVariances AS T2 ON T1.Rep_ID =
T2.Rep_ID
WHERE (((T2.Week_Numb er)>=[T1].[Week_Number]))
GROUP BY T1.Rep_ID, T2.Week_Number
ORDER BY T1.Rep_ID, T2.Week_Number;

You could use the results of this query as the input for your crosstab
table. I recommend Celko's "SQL for Smarties" - where I got this
query type.

Good luck,
Martin

Not sure if I understood this correctly - the references to T1 and T2
in particular.

The source for the qryVariances is a single table of Rep_ID,
Week_Number etc.

Do I need further reference tables (in the example above, T1, T2)
containing week and rep details?

TIA, much appreciated!

Matt

Nov 12 '05 #5

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

Similar topics

1
2487
by: Victor | last post by:
Hi There, I have a query witch gives me the following result: Period NumberOfItems 1 13 2 2 3 1 4 1 5 1
4
24518
by: cefrancke | last post by:
Are there any ways to speed up a Cumulative sum in a query or perhaps another faster way to have a cumulative sum column (call a vba function?). For example, I want to sum up all values under 'Amount', and also have a field call 'Cumulative' and have the sum grow with each record. Using "MyTable", the query results are... ID or Date Amount Cumulative --------------- ------ ----------
2
3216
by: chickenyd | last post by:
Hi i am trying to create a program using WML, WMLSCRIPT, AND JSP. The task is to create a website to be displayed in the WAP Browser. In the website for a company called 'BargainBook' that sells books and the ERD diagram for this is attached as picture (see attachement). So now I have just finished creating a login and register page and nearly done on purchase page BUT what I want to do is to find out how to display the MEAN and VARIANCE...
0
2483
by: James Hallam | last post by:
I have searched through the news groups and found many threads close to what I want but cannot get any of them to work... I have a table with expenses and invoices, what I want is a bar chart with value on the y-axis, time on the x-axis and two series... cumulative expenses and cumulative invoices so I can compare them against each other against time. What I have tried to do is create a runing sum column using the SQL code as...
3
6906
ChaseCox
by: ChaseCox | last post by:
Hi all, I have a problem that I have been looking at for a couple days now and I can not quite get it to work. I would like to calculate the cumulative percent failure of a certain product in my table. :: Cumulative Percent Failure Example: If you had 100 product shipped, and every month 10 units failed, you would have 10% failure the first month, 20% the second, and so on. The fields in my table that I am concerned with are ,...
1
2474
by: wisemen | last post by:
I have a table with 2 columns, and .I want to run a query that will give me a cumulative sum of the no. of entries that have an <= and on the second column give me a cumulative sum of the no. of entries for . These cumulative sums will be grouped by {Planned_Close_Date] Here is what the CODE I have so far, it does not give me cumulated sums. SELECT tblDataStore.PlannedCloseDate, Count(tblDataStore.PlannedCloseDate) AS...
1
2284
by: cbellew | last post by:
Hi guys, i'm looking to create a report with a table showing totals (running and cumulative) of education sessions attend by the staff at a hospital. I'm trying to get the table to show something like this: Month/Year | No. of sessions in this month | Cumulative total Jan 07 2 2 Feb 07 3 5...
3
5033
by: eliasam | last post by:
Hi can anyone help me with this? I've got a field in a query to calculate the weight charge: CalcWeightCharge: * Then in another field i would like to calculate the variance from the given charge to the calculated weight charge, so i have used: WeighChargeVar: -
4
1992
by: JAG | last post by:
The following line of code worked in my .hta prior to installing MS08-045 - Cumulative Security Update for Internet Explorer (953838) (on both XP and W2K): window.top.frames.location = ; After installing the above update on both XP and W2K, I had to change the above line to the following to get the same result: window.top.frames.location = ; I did a little research on the MS site but failed to get specifics on
0
9893
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
11001
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
10722
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9500
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7894
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
7069
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5735
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4544
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4137
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.