Results 1 to 8 of 8
  1. #1
    hmartin is offline Novice
    Windows XP Access 2007
    Join Date
    Jan 2012
    Posts
    5

    Query Expression Help

    Below is the expressions broken down into 1 column each.

    CABIHours: IIf([work hours]![work code]=60,[hours])
    CABIOTHours: [CABIHours]-8

    TotalCABIRate: IIf([CABIHours]>8,(500+([CABIHours]-8)*93.75),[CABIHours]*62.5)

    ProjectManagerHours: IIf([work hours]![work code]=14,[hours])

    ProjectManagerOTHours: [ProjectManagerHours]-8

    TotalProjectManagerRate: IIf([ProjectManagerHours]>8,(576+([ProjectManagerHours]-8)*95),[ProjectManagerHours]*72)

    AMSHours: IIf([work hours]![work code]=62,[hours])

    AMSOTHours: [AMSHours]-8


    TotalAMSRate: IIf([AMSHours]>8,(576+([AMSHours]-8)*95),[AMSHours]*72)

    I need these expressions to be on one line. Below is what I thought the correct expression would be.

    TotalRateAllPositions: (IIf([work hours]![work code]=60,[hours]),IIf([CABIHours]-8), IIf([CABIHours]>8,(500+([CABIHours]-8)*93.75),[CABIHours]*62.5), IIf([work hours]![work code]=14,[hours]),Iff([ProjectManagerHours]-8), IIf([ProjectManagerHours]>8,(576+([ProjectManagerHours]-8)*95),[ProjectManagerHours]*72), IIf([work hours]![work code]=62,[hours]),(IIF[AMSHours]-8), IIf([AMSHours]>8,(576+([AMSHours]-8)*95),[AMSHours]*72)))))))))

    I need this expression to calculate the normal hours for the CABI position, then calculate the overtime hours, then the rates for normal time and overtime. As you can see the CABI rates are different from the ProjectManager and AMS positions. The same goes for the ProjectManager and AMS positions. Any ideas? Your help would be greatly appreciated.

    Thanks,
    Holly

  2. #2
    hmartin is offline Novice
    Windows XP Access 2007
    Join Date
    Jan 2012
    Posts
    5
    I should have posted this expression. I get a comma error when I try to run it.

    TotalRateAllPositions: (IIf([CABIHours]>8,(500+([CABIHours]-8)*93.75),[CABIHours]*62.5),IIf([ProjectManagerHours]>8,(576+([ProjectManagerHours]-8)*95),[ProjectManagerHours]*72),IIf([AMSHours]>8,(576+([AMSHours]-8)*95),[AMSHours]*72))

  3. #3
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Quote Originally Posted by hmartin View Post
    I should have posted this expression. I get a comma error when I try to run it.

    TotalRateAllPositions: (IIf([CABIHours]>8,(500+([CABIHours]-8)*93.75),[CABIHours]*62.5),IIf([ProjectManagerHours]>8,(576+([ProjectManagerHours]-8)*95),[ProjectManagerHours]*72),IIf([AMSHours]>8,(576+([AMSHours]-8)*95),[AMSHours]*72))
    From your first post, these three expressions have improper syntax:
    Code:
    CABIHours: IIf([work hours]![work code]=60,[hours])
    ProjectManagerHours: IIf([work hours]![work code]=14,[hours])
    AMSHours: IIf([work hours]![work code]=62,[hours])
    The syntax is:

    Code:
    IIF(condition, TRUE clause, FALSE clause)
    You are missing the FALSE clause. It is not optional.
    Then when you use them in the TotalRateAllPositions expression, you are receiving an error. There are too many close parentheses and not enough commas.

    You have a 9 level nested IIF() function. That is a lot. It might be better to write a UDF.

    You can consolidate conditions... I would start out with the skeleton

    Code:
    IIF(condition, TRUE clause, FALSE clause)
    add the conditions:

    Code:
    IIF([work code]=60 or [work code]=14 or[work code]=62, TRUE clause, FALSE clause)
    then add the TRUE clause:

    Code:
    IIF([work code]=60 or [work code]=14 or[work code]=62, [hours], FALSE clause)
    You are going to have another IIF() statement, so add that as the FALSE clause:
    IIF([work code]=60 or [work code]=14 or[work code]=62, [hours], IIF(condition, TRUE clause, FALSE clause))
    Add another condition (in blue) for the 2nd IIF() function, add the TRUE clause, then add another IIF() as the FALSE clause. Continue building the expression until you a) are done or b) reach the max nesting limit.

  4. #4
    hmartin is offline Novice
    Windows XP Access 2007
    Join Date
    Jan 2012
    Posts
    5
    First of all thank you very much for you help. I was trying to use this expression in a query. I apologize but I don’t know how to write this as a code at all. I’m not sure what the FALSE clause would be. I would really appreciate your help. This is going to generate billing for a large job we were just awarded. I need to rate for each position worked each day.
    8 hours will be billed at $62.50 an hour for the CABI position

    Overtime anything over 8 hours in a day will be billed at $93.75 an hour for the CABI position

    8 hours will be billed at $72.00 an hour for the ProjectManager position

    Overtime anything over 8 hours in a day will be billed at $95.00 an hour for the ProjectManager position

    8 hours will be billed at $72.00 an hour for the AMS position

    Overtime anything over 8 hours in a day will be billed at $95.00 an hour for the AMS position

  5. #5
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    Quote Originally Posted by hmartin View Post
    First of all thank you very much for you help. I was trying to use this expression in a query. I apologize but I don’t know how to write this as a code at all. I’m not sure what the FALSE clause would be. I would really appreciate your help. This is going to generate billing for a large job we were just awarded. I need to rate for each position worked each day.
    8 hours will be billed at $62.50 an hour for the CABI position

    Overtime anything over 8 hours in a day will be billed at $93.75 an hour for the CABI position

    8 hours will be billed at $72.00 an hour for the ProjectManager position

    Overtime anything over 8 hours in a day will be billed at $95.00 an hour for the ProjectManager position

    8 hours will be billed at $72.00 an hour for the AMS position


    Overtime anything over 8 hours in a day will be billed at $95.00 an hour for the AMS position
    So the field [work code] differentiates which position?
    Is the following correct?

    [work code]=60 CABI
    [work code]=14 ProjectManager
    [work code]=62 AMS

    Are the hourly rates for ST & OT available in the query? If so, what are the field names? (I am trying not to hard code the rates.)

    Would you post the SQL of the query?
    Last edited by ssanfu; 01-20-2012 at 08:46 PM. Reason: added questioin

  6. #6
    hmartin is offline Novice
    Windows XP Access 2007
    Join Date
    Jan 2012
    Posts
    5
    Hello,

    Yes the work codes are correct. The ST and OT rates do not have field names. I only calculated the hours and not the rates. Below is the SQL. Again I really appreciate your help.
    SELECT IIf([work hours]![work code]=60,[hours]) AS CABIHours, [CABIHours]-8 AS CABIOTHours, IIf([CABIHours]>8,(500+([CABIHours]-8)*93.75),[CABIHours]*62.5) AS TotalCABIRate, IIf([work hours]![work code]=14,[hours]) AS ProjectManagerHours, [ProjectManagerHours]-8 AS ProjectManagerOTHours, IIf([ProjectManagerHours]>8,(576+([ProjectManagerHours]-8)*95),[ProjectManagerHours]*72) AS TotalProjectManagerRate, IIf([work hours]![work code]=62,[hours]) AS AMSHours, [AMSHours]-8 AS AMSOTHours, IIf([AMSHours]>8,(576+([AMSHours]-8)*95),[AMSHours]*72) AS TotalAMSRate, [Work Hours].ID, [Work Hours].Project, [Work Hours].Employee, [Work Hours].[Date Worked], [Work Hours].TimeIn, [Work Hours].TimeOut, [Work Hours].[Work Code], [Work Hours].Hours, [Work Hours].Notes, [Work Hours].Mileage, [Work Hours].[Equipment Used], [Work Hours].[Equipment Qty], [Work Hours].EquipmentRate, [Work Hours].[Per Diem Applies], [Work Hours].[Payroll Notes Date], [Work Codes].Description, [tbl Work Auth].ProjectNumber, [tbl Work Auth].*, tblProjectEquipment.*, [Project Expenses].*
    FROM ([Project Expenses] LEFT JOIN ([tbl Work Auth] LEFT JOIN ([Work Codes] RIGHT JOIN [Work Hours] ON [Work Codes].ID = [Work Hours].[Work Code]) ON [tbl Work Auth].ProjectNumber = [Work Hours].Project) ON [Project Expenses].ProjectNumberEX = [tbl Work Auth].ProjectNumber) LEFT JOIN tblProjectEquipment ON [tbl Work Auth].ProjectNumber = tblProjectEquipment.ProjectNumberEQU
    WHERE ((([tbl Work Auth].ProjectNumber)="012004"))
    ORDER BY [Work Hours].[Date Worked];

  7. #7
    ssanfu is offline Master of Nothing
    Windows 2K Access 2000
    Join Date
    Sep 2010
    Location
    Anchorage, Alaska, USA
    Posts
    9,664
    In looking at your query, it looks like there can be only one [work code] per record, so I didn't calculate the rates for all 3 positions per record.

    I created a query as a test and attached the SQL in a text file.
    Create a new query and paste in the SQL from the attachment "SS_Query.txt". This is to see if I am close on what you are trying to calculate.

    Then I merged part of my query with the SQL you posted. Create another new query and paste on the SQL from "hm_query.txt". Hopefully this will return the correct values.


    ---
    I would advise you to stop using spaces in object names. It will eventually cause you headaches.

  8. #8
    hmartin is offline Novice
    Windows XP Access 2007
    Join Date
    Jan 2012
    Posts
    5
    Oh my goodness! You did it! I cant thank you enough. You have been a huge help. May I pick you brain form time to time? Clearly you are an access expert! Thank you so much. It is greatly appreciated.

    Kind Regards,
    Holly

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Query Expression
    By nizam in forum Queries
    Replies: 1
    Last Post: 11-12-2011, 02:56 PM
  2. Expression for Query Help
    By fikeplay in forum Access
    Replies: 1
    Last Post: 07-09-2011, 05:12 PM
  3. Need help Modifying a query expression
    By leslina76 in forum Queries
    Replies: 3
    Last Post: 04-02-2011, 08:45 AM
  4. Sum problem for query expression
    By Stanggirlie in forum Access
    Replies: 3
    Last Post: 09-18-2009, 05:54 AM
  5. Replies: 0
    Last Post: 12-05-2005, 04:09 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums