Results 1 to 2 of 2
  1. #1
    cbh35711 is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Feb 2012
    Posts
    40

    IIF Grouping Query Problem

    Hello all,



    Writing a query to take some data that is in a single column and partition it out by section. However, i'm hitting a problem that i cannot resolve. When i run the code below, it errors saying that i'm not including IIF(Section="1", sum(Breaks), null) in the group by. But that doesn't make any sense. My goal is to have one line with the sum(breaks) in each section(per AddDate, type).

    Code:
    select AddDate, Type,
    IIF(Section="1", sum(Breaks), null) as [# of PD breaks], 
    IIF(Section="2", sum(Breaks), null) as [# of Entries NOT in RA], 
    IIF(Section="3", sum(Breaks), null) as [# of Entries NOT in CCR log] 
    from trend_data
    group by AddDate, type;

    I can run this code, but it doesn't flatten the records into one. It just shows nulls in the additional columns, which is exactly what it should do.
    Code:
    select AddDate, Type, section
    IIF(Section="1", sum(Breaks), null) as [# of PD breaks], 
    IIF(Section="2", sum(Breaks), null) as [# of Entries NOT in RA], 
    IIF(Section="3", sum(Breaks), null) as [# of Entries NOT in CCR log] 
    from trend_data
    group by AddDate, type,section;

    Any advice would be greatly appreciated.

    Thanks,

    Chris

  2. #2
    cbh35711 is offline Advanced Beginner
    Windows 7 32bit Access 2007
    Join Date
    Feb 2012
    Posts
    40
    Had a thought... Sums on the outside of the IIF, not inside. Worker like a charm.

    Code:
    select AddDate, Type,
    Sum(IIF(Section="1", Breaks, null)) as [# of PD breaks], 
    sum(IIF(Section="2", Breaks, null)) as [# of Entries NOT in RA], 
    sum(IIF(Section="3", Breaks, null)) as [# of Entries NOT in CCR log] 
    from trend_data
    group by AddDate, type;

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

Similar Threads

  1. Grouping query with percentage
    By msadiqrajani in forum Queries
    Replies: 1
    Last Post: 03-16-2012, 02:14 PM
  2. typical query on grouping
    By johnbest in forum Access
    Replies: 2
    Last Post: 03-13-2012, 10:36 PM
  3. Grouping, Summing, and Ranking Problem
    By cadsvc in forum Reports
    Replies: 3
    Last Post: 04-16-2011, 11:34 AM
  4. Grouping hours query
    By DMP84 in forum Queries
    Replies: 0
    Last Post: 08-26-2010, 07:15 AM
  5. Grouping query
    By Mphiri in forum Programming
    Replies: 10
    Last Post: 06-15-2010, 08:58 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