Results 1 to 10 of 10
  1. #1
    andydarly is offline Novice
    Windows 7 64bit Access 2013 32bit
    Join Date
    Mar 2017
    Posts
    6

    IIf / And formula


    Hi, all.

    I am trying to write a formula for query builder and it's close but not quite right... I have a table with effectively calls answered and another with calls abandoned within them. I have taken what I need from those tables and discarded what I don't need to give me dates, interval periods etc for answered and another for abandoned. all pretty straightforward so far...

    Now what I am looking to do is to merge those two tables and everything works fine except for the Abandoned numbers within the query based on the original two queries being slightly out.

    The fields in the original queries are named SumOfInteractions Answered by Agent for Calls Answered and Total Abandoned Calls for Abandoned. There is another field called Interaction Type that will either have the value Inbound or Outbound.

    I basically want the formula I am trying to write say that if the Calls Answered and Abandoned are both zero don't enter anything, if the Calls Answered is zero and Abandoned > zero then put the Abandoned, if Calls Answered is greater than zero and Abandoned is zero, set abandoned to zero (or blank), if Calls Answered and Abandoned are both greater than zero then put abandoned. All of these need to be under the condition that if Interaction Type is Outbound then Abandoned Calls is zero (or blank) and to only enter the value for Abandoned if Interaction Type has the value Inbound.

    I really hope that makes sense. the Calls Answered field has its own field in the new query and the numbers coming out of that are fine so I am not currently concerned with that. The code I have come up with is the below but like I say it isn't quite there...


    Abandoned Calls: Sum(IIf([SumOfInteractions Answered by Agent] Is Null And [Total Abandoned Calls] Is Null,0,IIf([Interaction Type]="Outbound",0,[Total Abandoned Calls])))


    Am I woefully off? I am really quite new to Access so if you could give me the kind of answer even an idiot would understand then I would be very grateful.

    thanks in advance.

    Andy

  2. #2
    orange's Avatar
    orange is online now Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    Welcome to the forum.

    Show your table(s) design and the SQL of the query(s). We need to see some details.

  3. #3
    andydarly is offline Novice
    Windows 7 64bit Access 2013 32bit
    Join Date
    Mar 2017
    Posts
    6
    Hi, not sure how to show table design or what I would include but the SQL of the query is


    SELECT qry_IB_Interval_Ans_1617Q3.[Yr & Wk], qry_IB_Interval_Ans_1617Q3.Date, qry_IB_Interval_Ans_1617Q3.[Time Slice 30min], qry_IB_Interval_Ans_1617Q3.[Service Group Level 1 (SG1)], qry_IB_Interval_Ans_1617Q3.[Service Group Level 2 (SG2)], qry_IB_Interval_Ans_1617Q3.[Service Group Level 3 (SG3)], qry_IB_Interval_Ans_1617Q3.[Service Call Type (SCT)], Sum(IIf([SumOfInteractions Answered by Agent] Is Null,0,[SumOfInteractions Answered by Agent])+IIf([Total Abandoned Calls] Is Null,0,[Total Abandoned Calls])) AS CallsOffered, Sum(qry_IB_Interval_Ans_1617Q3.[SumOfInteractions Answered by Agent]) AS [SumOfSumOfInteractions Answered by Agent], Sum(IIf([SumOfInteractions Answered by Agent] Is Null And [Total Abandoned Calls] Is Null,0,IIf([Interaction Type]="Outbound",0,[Total Abandoned Calls]))) AS [Abandoned Calls], Sum(qry_IB_Interval_Ans_1617Q3.[SumOfTotal Handle Time]) AS [SumOfSumOfTotal Handle Time], Sum(qry_IB_Interval_Ans_1617Q3.[SumOfAgent Total Talk Duration]) AS [SumOfSumOfAgent Total Talk Duration], Sum(qry_IB_Interval_Ans_1617Q3.[SumOfHold Duration]) AS [SumOfSumOfHold Duration], Sum(qry_IB_Interval_Ans_1617Q3.[SumOfTotal ACW Duration]) AS [SumOfSumOfTotal ACW Duration], Sum(qry_IB_Interval_Ans_1617Q3.[SumOfIVR Duration]) AS [SumOfSumOfIVR Duration], qry_IB_Interval_Ans_1617Q3.[Interaction Type]
    FROM qry_IB_Interval_Ans_1617Q3 LEFT JOIN qry_IB_Interval_Abandoned_1617Q3 ON (qry_IB_Interval_Ans_1617Q3.[Time Slice 30min] = qry_IB_Interval_Abandoned_1617Q3.[Timeslice 30 Mins]) AND (qry_IB_Interval_Ans_1617Q3.[Service Call Type (SCT)] = qry_IB_Interval_Abandoned_1617Q3.[Service Call Type (SCT)]) AND (qry_IB_Interval_Ans_1617Q3.Date = qry_IB_Interval_Abandoned_1617Q3.Date)
    GROUP BY qry_IB_Interval_Ans_1617Q3.[Yr & Wk], qry_IB_Interval_Ans_1617Q3.Date, qry_IB_Interval_Ans_1617Q3.[Time Slice 30min], qry_IB_Interval_Ans_1617Q3.[Service Group Level 1 (SG1)], qry_IB_Interval_Ans_1617Q3.[Service Group Level 2 (SG2)], qry_IB_Interval_Ans_1617Q3.[Service Group Level 3 (SG3)], qry_IB_Interval_Ans_1617Q3.[Service Call Type (SCT)], qry_IB_Interval_Ans_1617Q3.[Interaction Type]
    HAVING (((qry_IB_Interval_Ans_1617Q3.Date)=#3/6/2017#))
    ORDER BY qry_IB_Interval_Ans_1617Q3.Date, qry_IB_Interval_Ans_1617Q3.[Time Slice 30min];


    Does that help?

    many thanks

    Andy

  4. #4
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    If interaction type = "inbound" then use what is in the abandoned field otherwise it is zero/blank.

  5. #5
    orange's Avatar
    orange is online now Moderator
    Windows 10 Access 2010 32bit
    Join Date
    Sep 2009
    Location
    Ottawa, Ontario, Canada; West Palm Beach FL
    Posts
    16,726
    No, the long sql doesn't help me, but it may be helpful to others.
    Your sql revolves around a query qry_IB_Interval_Ans_1617Q3
    which we know nothing about.

    Do you have anything in your relationships window? Database Tools-->Relationships

  6. #6
    andydarly is offline Novice
    Windows 7 64bit Access 2013 32bit
    Join Date
    Mar 2017
    Posts
    6
    Hi, thanks for this. I get exactly the same results as the original formula though

  7. #7
    aytee111 is offline Competent At Times
    Windows 10 Access 2013 64bit
    Join Date
    Nov 2011
    Location
    Nomad
    Posts
    3,936
    What is the problem?

  8. #8
    NTC is offline VIP
    Windows 10 Access 2013
    Join Date
    Nov 2009
    Posts
    2,392
    Abandoned Calls: IIf([IsNull([SumOfInteractions Answered by Agent]) AND IsNull([Total Abandoned Calls]),0,IIf([Interaction Type]="Outbound",0,[Total Abandoned Calls]))

  9. #9
    andydarly is offline Novice
    Windows 7 64bit Access 2013 32bit
    Join Date
    Mar 2017
    Posts
    6
    Hi, thanks for that.

    Not sure if there is something missing but I get the error "The expression you entered has a function containing the wrong number of arguments".

    Not sure if its a comma, a bracket, the order...I just don't know enough

  10. #10
    NTC is offline VIP
    Windows 10 Access 2013
    Join Date
    Nov 2009
    Posts
    2,392
    there was a left [ before the first IsNull in error

    Abandoned Calls: IIf(IsNull([SumOfInteractions Answered by Agent]) AND IsNull([Total Abandoned Calls]),0,IIf([Interaction Type]="Outbound",0,[Total Abandoned Calls]))

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

Similar Threads

  1. Formula Help
    By bstack10 in forum Access
    Replies: 2
    Last Post: 04-18-2016, 03:13 AM
  2. Replies: 19
    Last Post: 07-13-2015, 10:15 AM
  3. Replies: 41
    Last Post: 05-29-2015, 02:58 PM
  4. Formula
    By Ray67 in forum Queries
    Replies: 53
    Last Post: 08-09-2012, 01:56 AM
  5. Formula
    By hschrunk in forum Access
    Replies: 3
    Last Post: 05-18-2010, 01:40 PM

Tags for this Thread

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