I
Ian
Hello, all.
I am building a fairly simple time tracking DB. One of the reports I need to
write calculates the persons Comp Time on a weekly basis. There are two types
of employees: Hourly and Salaried. For Hourly, anything over 40 accrues comp
time; for Salaried, anything over 45 does so.
I have a report with two groupings: Week number inside Employee number. Week
number is defined as DatePart("ww","tblTimeEntries.tdate), or the week number
part taken out of the week the time was reported. This works fine.
Within that grouping, I have no problems calculating the correct number of
hours they "should" work as
=IIf([PersonType]="Salaried",45,40)
and in the Employee group, I just SUM that and it gives me the correct
number of hours they should have worked.
Also in the weekly grouping, I calculate the hours they did work as:
=Sum(IIf([tjob]<>'X0012',([tStopTime]-[tStartTime])*24,0))
[note that tjob is a job code, and X0012 represents lunch. They don't get
credit for this time.
Again, Putting this in the Employee group using a sum gives me what I expect.
Now, in order to get the number of hours comp time they are due that week, I
just subtract them, with the additional caveat that if less than 0, they are
due 0 hours. In the week group, that looks like:
=IIf(Sum(IIf([tjob]<>'X0012',([tStopTime]-[tStartTime])*24,0))-IIf([PersonType]="Salaried",45,40)<0,0,Sum(IIf([tjob]<>'X0012',([tStopTime]-[tStartTime])*24,0))-IIf([PersonType]="Salaried",45,40))
And that seems to work fine for each week.
Now the difficulty:
If I then take that expression and put it into the Employee group, thus:
=SUM(IIf(Sum(IIf([tjob]<>'X0012',([tStopTime]-[tStartTime])*24,0))-IIf([PersonType]="Salaried",45,40)<0,0,Sum(IIf([tjob]<>'X0012',([tStopTime]-[tStartTime])*24,0))-IIf([PersonType]="Salaried",45,40)))
I get an error 3095, cannot have aggregate function in expression.
How can I fix this? My SQL is not up to calculating the weekly available
time in a Query, althought that seems like it might work. Is that the answer?
Thanks for the help. I really appreciate it.
///Ian
I am building a fairly simple time tracking DB. One of the reports I need to
write calculates the persons Comp Time on a weekly basis. There are two types
of employees: Hourly and Salaried. For Hourly, anything over 40 accrues comp
time; for Salaried, anything over 45 does so.
I have a report with two groupings: Week number inside Employee number. Week
number is defined as DatePart("ww","tblTimeEntries.tdate), or the week number
part taken out of the week the time was reported. This works fine.
Within that grouping, I have no problems calculating the correct number of
hours they "should" work as
=IIf([PersonType]="Salaried",45,40)
and in the Employee group, I just SUM that and it gives me the correct
number of hours they should have worked.
Also in the weekly grouping, I calculate the hours they did work as:
=Sum(IIf([tjob]<>'X0012',([tStopTime]-[tStartTime])*24,0))
[note that tjob is a job code, and X0012 represents lunch. They don't get
credit for this time.
Again, Putting this in the Employee group using a sum gives me what I expect.
Now, in order to get the number of hours comp time they are due that week, I
just subtract them, with the additional caveat that if less than 0, they are
due 0 hours. In the week group, that looks like:
=IIf(Sum(IIf([tjob]<>'X0012',([tStopTime]-[tStartTime])*24,0))-IIf([PersonType]="Salaried",45,40)<0,0,Sum(IIf([tjob]<>'X0012',([tStopTime]-[tStartTime])*24,0))-IIf([PersonType]="Salaried",45,40))
And that seems to work fine for each week.
Now the difficulty:
If I then take that expression and put it into the Employee group, thus:
=SUM(IIf(Sum(IIf([tjob]<>'X0012',([tStopTime]-[tStartTime])*24,0))-IIf([PersonType]="Salaried",45,40)<0,0,Sum(IIf([tjob]<>'X0012',([tStopTime]-[tStartTime])*24,0))-IIf([PersonType]="Salaried",45,40)))
I get an error 3095, cannot have aggregate function in expression.
How can I fix this? My SQL is not up to calculating the weekly available
time in a Query, althought that seems like it might work. Is that the answer?
Thanks for the help. I really appreciate it.
///Ian