How to calculate cumulative values of this query fields?

tony007

Registered User.
Local time
Today, 12:53
Joined
Jun 30, 2005
Messages
53
Hi everybody. I got a access 2000 query that lists :

1)weekno
2)year
3)project (project number )
4)QweekylyReportHeader (project description )
5)customer (customer that requested this project)
6)department (department number and name that implements this project)
7)Projectleader ( project leader name and number that is responsible for this project)
8)Task (Task number that is done for this project )
9)task description (description of task )
10)employee ( employee number who is working in this project )
11)name (Employee name and initial and last that works for this project )


12)hours ( number of hours employee worked in this task ) ==> i want cumulative for this
13)salary (amount of salary given to this employee) ===>i want cumulative for this


I want to create another query that lists :

A)cumulative value of hours worked on particular project task up that point.
b)cumulative value for wages given for that project task up that point.

http://i5.photobucket.com/albums/y180/method007/weeklyprojectdata2.jpg ( query output sample)

The above query ONLY lists hours worked and wages gives for particular project task only during
each week.But i want hours worked and wages give for particle project task up to that point in week. For
example a project task might have implemented last week but not this so i want to take that in calculation as well.
I be happy if some expert show me how i can calculate the cumulative value for hours worked and wages given for particular
project task.



Notes:


- There is a possibility that during a particular week no task been implement for particular project.
- One employee can work in more then one project
- One employee can have more then one salary (amount) for the same
project because he might get raise in salary!
- Only tasks carried this week will be printed in the weekly report

http://i5.photobucket.com/albums/y180/method007/constraint.jpg ( pic of database)
http://i5.photobucket.com/albums/y180/method007/hourlywagesroportfinal.jpg ( query output population)
http://i5.photobucket.com/albums/y180/method007/queryindesign.jpg (query in design view)


query that display hourly wages of certain project during each week
Code:
SELECT 
querythisweek.weekno,
 querythisweek.Year,
 querythisweek.Project, 
QweeklyReportHeader.Customer, 
QweeklyReportHeader.Department, 
QweeklyReportHeader.description,
 QweeklyReportHeader.ProjectLeader,
 querythisweek.Task,
 dbo_Task.description,
 querythisweek.Employee, 
[lastname] & ' ' & [initials] & ' ' & [insertion] AS Name,
 querythisweek.hours, 
querythisweek.Salary
FROM 
dbo_Task 
INNER JOIN ((QweeklyReportHeader INNER JOIN querythisweek ON QweeklyReportHeader.projectno = querythisweek.Project) INNER JOIN dbo_Employee ON querythisweek.Employee = dbo_Employee.employeeno) ON dbo_Task.taskcode = querythisweek.Task;

code for querythis week( calcualte the salary and hours worked)

Code:
SELECT dbo_Hours_worked.Project, dbo_Hours_worked.Year, dbo_Hours_worked.weekno, dbo_Hours_worked.Task, dbo_Hours_worked.Employee, dbo_Hours_worked.hours, (select a.amount * dbo_Hours_worked.hours
      from dbo_Hourly_wages a 
      where dbo_Hours_worked.Employee = a.Employee 
      and dbo_Hours_worked.Project = a.Project 
      and a.Year * 100 + a.weekno = (select max(b.Year *100 + b.weekno)
                                                            from dbo_Hourly_wages b
                                                            where b.Year < dbo_Hours_worked.Year
                                                            or (b.Year = dbo_Hours_worked.Year and b.weekno <= dbo_Hours_worked.weekno))) AS Salary
FROM dbo_Hours_worked;
 
Last edited:
In general, you can make a "cumulative value" query, including what you have presented in your screenshots. However, to do it effectively, you need to normalize your current tables more. For instance, you have two tables called "dbo_Hourly_wages" and "dbo_Hours_worked that contains duplicative data. To create a cumulative value table, you need to have a query based on unique values, so an alias table can be created from these tables to provide the cumulative value seed.

Is it possible to post your zipped database structure with sample data so we can see the actual relationships?
 
mresann said:
In general, you can make a "cumulative value" query, including what you have presented in your screenshots. However, to do it effectively, you need to normalize your current tables more. For instance, you have two tables called "dbo_Hourly_wages" and "dbo_Hours_worked that contains duplicative data. To create a cumulative value table, you need to have a query based on unique values, so an alias table can be created from these tables to provide the cumulative value seed.

Is it possible to post your zipped database structure with sample data so we can see the actual relationships?
Thank u for your reply. Well at this moment i do not want to normalize it. I posted the query that is calculating the hours and salary for each week only . could u help me using that to calculate the cumulitve values.Thanks
 
Take this qualifyer out of your query:
Code:
and a.Year * 100 + a.weekno = (select max(b.Year *100 + b.weekno)
 
neileg said:
Take this qualifyer out of your query:
Code:
and a.Year * 100 + a.weekno = (select max(b.Year *100 + b.weekno)

well i can not take the part out. Since that part calculates the corect wages for each project employee is engaged in. The employee gets raise and that max function finds his latest salary .IF i remove that part the wages will be not be calculated corectly!!
 
No, I meant copy this query and remove the qualifyer. Maybe I have misunderstood.

Anyway, you won't get the current week and the total to date in the same select query. If you want them both in the same query, you have to take two select queries and create a union query. This will then have two records, one for the week and one for the cumulative.
 

Users who are viewing this thread

Back
Top Bottom