Count Distinct Wtih CASE Statement - Does not follow aggregation path

All,
I have a fact table, a day aggregate and a month aggregate. I have a time hierarchy and the month aggregate is set to the month level, the day aggregate is set to the day level within the time hierarchy.
When using any measures and a field from my time dimension .. the appropriate aggregate is chosen, ie month & activity count .. month aggregate is used. Day & activity count .. day aggregate is used.
However - when I use the count distinct aggregate rule .. the request always uses the lowest common denominator. The way I have found to get this to work is to use a logical table source override in the aggregation tab. Once I do this .. it does use the aggregates correctly.
A few questions
1. Is this the correct way to use aggregate navigation for the count distinct aggregation rule (using the source override option)? If yes, why is this necessary for count distinct .. what is special about it?
2. The main problem I have now is that I need to create a simple count measure that has a CASE statement in it. The only way I see to do this is to select the Based on Dimensions checkbox which then allows me to add a CASE statement into my count distinct clause. But now the aggregation issue comes back into play and I can't do the logical table source override when the based on dimensions checkbox is checked .. so I am now stuck .. any help is appreciated.
K

Ok - I found a workaround (and maybe the preferred solution for my particular issue), which is - Using a CASE Statement with a COUNT DISTINCT aggregation and still havine AGGREGATE AWARENESS
To get all three of the requirements above to work I had to do the following:
- Create the COUNT DISTINCT as normal (counting on a USERID physically mapped column in my case)
- Now I need to map my fact and aggregates to this column. This is where I got the case statement to work. Instead of trying to put the case statement inside of the Aggregate definition by using the checkbox 'Base on Dimension' (which didnt allow for aggregate awareness for some reason) .. I instead specified the case statement in the Column Mapping section of the Fact and Aggregate tables.
- Once all the LTS's (facts and aggregates) are mapped .. you still have to define the Logical Table Source overrides in the aggregate tab of the count distinct definition. Add in all the fact and aggregates.
Now the measure will use my month aggregate when i specify month, the day aggregate when i specify day, etc..
If you are just trying to use a Count Distinct (no CASE satement needed) with Aggregate Awareness, you just need to use the Logical Table Source override on the aggregate tab.
There is still a funky issue when using the COUNT aggregate type. As long as you dont map multiple logical table sources to the COUNT column it works fine and as expected. But, if you try to add in multiple sources and aggregate awareness it randomly starts SUMMING everything .. very weird. The blog in this thread says to check the 'Based on Dimension' checkbox to fix the problem but that did not work for me. Still not sure what to do on this one .. but its not currently causing me a problem so I will ignore for now ;)
Thanks for all the help
K

Similar Messages

  • Count distinct in case statement

    SELECT A.P_ID,
    B.P_NAME,
    C.P_DESC,
    SUM(CASE
    WHEN A.DATE BETWEEN TRUNC(ADD_MONTHS(LAST_DAY(SYSDATE),-4) + 1) AND ADD_MONTHS(LAST_DAY(TO_DATE(SYSDATE)),-1)
    AND A.M_ID IS NOT NULL
    THEN 1
    ELSE 0
    END) AS COUNT,
    SUM(CASE
    WHEN A.DATE BETWEEN TRUNC(ADD_MONTHS(LAST_DAY(SYSDATE),-4) + 1) AND ADD_MONTHS(LAST_DAY(TO_DATE(SYSDATE)),-1)
    AND A.M_ID IS NOT NULL
    THEN COUNT(DISTINCT A.M_ID)
    ELSE 0
    END) AS UNIQUE_COUNT, /* Not possible */
    SUM(CASE
    WHEN A.DATE BETWEEN TRUNC(SYSDATE,'YEAR') AND ADD_MONTHS(LAST_DAY(TO_DATE(SYSDATE)),-1)
    THEN A.AMT_1
    ELSE 0
    END) AS TOTAL_AMT_1,
    SUM(CASE
    WHEN A.DATE BETWEEN TRUNC(SYSDATE,'YEAR') AND ADD_MONTHS(LAST_DAY(TO_DATE(SYSDATE)),-1)
    THEN A.AMT_2
    ELSE 0
    END) AS TOTAL_AMT_2
    FROM TABLE_A A,
    TABLE_B B,
    TABLE_C C
    WHERE A.P_ID = B.P_ID
    AND B.PT_ID = C.PT_ID
    GROUP BY A.P_ID,
    B.P_NAME,
    C.P_DESC
    Hi,
    This is a simplified version of my query.
    I am trying to do 4 things here,
    1. count A.M_ID
    2. count distinct A.M_ID, this is where I have a problem.
    3. and 4. Its just the sum from 2 diff columns.
    Note that the dates for count and amt are different and I can't hard code them.
    Can any one help me in the distinct count step?
    This query is also running kinda slow.
    So any suggestions, comments are very welcome.
    Note: TABLE_A has 700 million recs, TABLE_B 4 million and TABLE_c is just 500 recs
    Thanks!

    Taking advantage of the fact that most aggregate functions ignore nulls, you could do something like:
    SELECT a.p_id, b.p_name, c.p_desc,
           COUNT(CASE WHEN a.date BETWEEN TRUNC(ADD_MONTHS(LAST_DAY(sysdate),-4) + 1) AND
                                          ADD_MONTHS(LAST_DAY(TO_DATE(sysdate)),-1) AND
                           a.m_id IS NOT NULL THEN m_id END) AS countall,
           COUNT(DISTINCT CASE WHEN a.date BETWEEN TRUNC(ADD_MONTHS(LAST_DAY(sysdate),-4) + 1) AND
                                        ADD_MONTHS(LAST_DAY(TO_DATE(sysdate)),-1) AND
                         a.m_id IS NOT NULL THEN a.m_id END) AS unique_count, /* entirely possible */
           SUM(CASE WHEN a.date BETWEEN TRUNC(sysdate,'YEAR') AND
                                        ADD_MONTHS(LAST_DAY(TO_DATE(sysdate)),-1) THEN a.amt_1
                    ELSE 0 END) AS total_amt_1,
           SUM(CASE WHEN A.DATE BETWEEN TRUNC(sysdate,'YEAR') AND
                                        ADD_MONTHS(LAST_DAY(TO_DATE(sysdate)),-1) THEN A.AMT_2
                    ELSE 0 END) AS TOTAL_AMT_2
    FROM table_a a, table_b b, table_c c
    WHERE a.p_id = b.p_id and
          b.pt_id = c.pt_id
    GROUP BY a.p_id, b.p_name, c.p_descThe two case statements inside the COUNT return either a.m_id or NULL. A simplified test case is:
    SQL> WITH t as (
      2     SELECT 1 m_id, 9 dt FROM dual UNION ALL
      3     SELECT 1 m_id, 6 dt FROM dual UNION ALL
      4     SELECT 2 m_id, 9 dt FROM dual UNION ALL
      5     SELECT 2 m_id, 6 dt FROM dual UNION ALL
      6     SELECT 1 m_id, 5 dt FROM dual UNION ALL
      7     SELECT 2 m_id, 5 dt FROM dual UNION ALL
      8     SELECT null m_id, 9 dt FROM dual)
      9  SELECT count(CASE WHEN dt BETWEEN 6 and 9 THEN m_id end) cid,
    10         count(distinct CASE WHEN dt BETWEEN 6 and 9 THEN m_id end) cdid
    11  FROM t;
           CID       CDID
             4          2I'm not entirely sure that you actually need the a.m_id IS NOT NULL predicate in the CASE statements, but I left it to be safe.
    John

  • CASE Statement is not working Derived table

    Hi All,
    in the bello SQL Statement case statement is not working in derived table. I am new to creation of derived table if any body knows plz kinldy help me out on this.
    SELECT x.market, x.droprate as med1
    FROM
    (select upper(market_name) as market, fulldate as date_value,
         (sum([Dy_LOT_DROPS_N][Dy_OB_HO_DROPS][Dy_NonRF_Drop]))/
              nullif(sum(CASE WHEN (month(BBHDLY.FullDate)}>= 6 and { year(BBHDLY.FullDate)} = 2011) or {fn year(IDENSLABBHDLY.FullDate)} > 2011
    THEN  BBHDLY.Dy_Calls - BBHDLY.Dy_HO_CHAN_ALLOC ELSE BBHDLY.Dy_Calls END),0)*100 as droprate
    from BBHDLY sla
    inner join Dim mkt
         on sla.bts_name = mkt.bts_name and sla.SectorID = mkt.Sector_Id
                   where fulldate >= GETDATE()-46
                   group by market_name, fulldate) x,
    (select market_name as market, fulldate as date_value,
    (sum([Dy_LOT_DROPS_N][Dy_OB_HO_DROPS][Dy_NonRF_Drop]))/
              nullif(sum(CASE WHEN ({fn month(BBHDLY.FullDate)}>= 6 and {fn year(BBHDLY.FullDate)} = 2011) or {fn year(BBHDLY.FullDate)} >
    2011 THEN  BBHDLY.Dy_Calls - BBHDLY.Dy_HO_CHAN_ALLOC ELSE BBHDLY.Dy_Calls END),0)*100 as droprate
    from BBHDLY sla
    inner join Dim mkt
         on sla.bts_name = mkt.bts_name and sla.SectorID = mkt.Sector_Id
                   where fulldate >=GETDATE()-46
                   group by market_name, fulldate) y
    where x.market = y.market
    GROUP BY x.droprate, x.market
    HAVING
       SUM(CASE WHEN y.droprate <= x.droprate
          THEN 1 ELSE 0 END)>=(COUNT(*)+1)/2 AND
       SUM(CASE WHEN y.droprate >= x.droprate
          THEN 1 ELSE 0 END)>=(COUNT(*)/2)+1
    Thanks

    It looks like SQL Server or Sybase given that you're using getdate().
    As such, Vinesh's comment to use decode is wrong - decode is  Oracle syntax.
    Looking at your statement again, I've noticed the following:
    you have no { to match the first } - not sure why you're using them anyway.
    you haven't given x.market a name - use x.market as market instead
    use coalesce instead of nullif if you're on SQL Server.

  • All photos does not follow the stream

    Seemingly only random pictures does not follow the photo stream from iphone to macbook - any clues how that can happen, or where I start the troubleshooting..?

    ..and a little bit more specific:
    I noticed that some photos in the iPhone photo album doesn´t appear in the photo stream. I cannot find a continous error in this behaviour: this summer I noticed that every other picture was missing in the stream, but just from one weekend. Last weekend just ONE picture in the album was missing in the stream.
    It´s really odd, wouldn´t you say?
    I haven´t really made full follow-up during the autumn, since I hoped this phenomena would "disappear" along with the continous upgrading of iPhone, Macbook, iPhoto etc. So, it must be the Cloud that behaves strangely...?
    The one picture from last weekend was imported to iPhoto when connecting iPhone and macbook "by cord" along with the videos,
    The thing with the iCloud photo stream shod be that you wouldnt have to keep track of your photos by counting them or relying on cord connection, right?
    Any ideas, anyone?

  • I have consolidate my folders related to the video I am in the progress of working on.  Premiere elements does not follow their new location.  How do I syn them back up all at once so premiere doesn't ask me for their location when I open the project

    I have consolidate my folders related to the video I am in the progress of working on.  Premiere elements does not follow their new location.  How do I syn them back up all at once so premiere doesn't ask me for their location when I open the project

    This is the Photoshop Elements forum, not the Premiere Elements forum, located here:
    https://forums.adobe.com/community/premiere_elements
    When you open the project, it should ask you where the first file is located. After you tell it where it is, it should be able to find the rest of them if they are located near the first one.  Then save the file.  If you move the files again, you will have to relink them again.

  • Report Does Not Follow Select Column Order

    Hi all,
    Apex 2.2 on 10gXE
    I always encounter this problem, the display column on report does not follow the select column sequence order in the "region source".
    It is very tedious clicking the up/down arrow one-by-one in the "report attributes" especially if the display columns are plenty like 40 columns.
    Is there a fix/patch or alternative tips for this bug?
    Thanks a lot,
    Edited by: 843228 on May 24, 2011 10:32 PM

    Apex 2.2 on 10gXEStart by upgrading from this old unsupported version.
    >
    I always encounter this problem, the display column on report does not follow the select column sequence order in the "region source".
    It is very tedious clicking the up/down arrow one-by-one in the "report attributes" especially if the display columns are plenty like 40 columns.
    Is there a fix/patch or alternative tips for this bug?
    >
    This is not a bug. APEX maintains the original column order of the report. This avoids problems downstream in areas like the processing of <tt>g_fnn</tt> arrays in declarative tabular forms, where the assigned arrays are column-order dependent.
    APEX 4.x fixes column ordering bugs that could lead to report corruption, and includes drag-and-drop column ordering in the new tree view in addition to the up/down arrow re-ordering.
    If you really want column order to follow that in the source query, the workaround is to create a new report using the modified query.

  • I am getting this error message while accessing IT2002 Counting rule 2/01/001 does not exist Message no. 3H010

    hi All,
    I am getting this error message while accessing IT2002
    Counting rule 2/01/001 does not exist
    Message no. 3H010
    Please guide ASAP
    Regards,
    Ayousef

    Hi Ahmed,
    Please go through the below mentioned thread.
    scn.sap.com/thread/1187160
    Regards,
    Haranath

  • Process does not follow the routing ends up in complete status

    Installed Adobe LiveCycle server ES 2.5 with SQL Server 2008 as database
    And followed the tutorial ‘Create Your First LiveCycle Application’
    Deployed it on the server when I test the same
    i.e. when the workspace user fills in form details and hits complete button it ends up as status complete
    And not assigned to next user in the route
    The process does not follow the routing it ends up in complete status
    And nothing shows up when trying to record and play back the process
    Tried invoking Via workbench too
    no errors in the server log
    Could this be an installation issue any pointers appreciated
    Please advise

    Issue with Jboss as it was taking longtime time to start due to low CPU ideally it should not take more than 3 to 5 minutes
    Process works now

  • VO does not follow anchor link

    I find it strange that VocieOver in Mac OS X (10.5.8) does not follow anchor links. The W3C specification documents and Wikipedia use them a lot; however the VoiceOver box does not follow the link while Safri jumps to that part of the page.
    Is this a miss configuration at my part or has it been designed that way?
    Thanks

    Hi there
    Your description seems to imply you are narrating at the same time as you are recording. This isn't best practice. Your best results will be obtained by adding the audio as a separate activity after you have recorded the screen action.
    Often in a web recording we notice what is perceived as a  mismatch. Often you end up with blank slides. This is because Captivate is running on your local PC (and running very quickly). But when you click a link to a web page, what really happens is that you send a command from your PC across the internet to a Web Server. The Web Server has to process that command, look up the desired page, send the page across the internet to your PC and it finally displays. While it may seem that it happens swiftly, compared to Captivate running on the PC it takes eons.
    Cheers... Rick
    Click here for Adobe Certified Captivate and RoboHelp HTML Training
    Click here for the SorcerStone Blog
    Click here for RoboHelp and Captivate eBooks

  • Jewel case insert does not print properly since new itunes version was installed

    jewel case insert does not print properly since new itunes version was installed. The song list prints all of the line items too close together without space inbetween each song.

    I am having the same issue. If I close itunes and open with a new CD already in the drive, it will find it. But once that CD has been imported and ejected, itunes does not find the newly inserted CD and there is no command to tell itunes to "look" in the CD drive

  • HT3211 My tracking pad is not working. It controls itself and does not follow my finger commands. If I bring it to an apple store, would I be able to have a new pad installed?

    My tracking pad is not working. It controls itself and does not follow my finger commands. If I bring it to an apple store, would I be able to have a new pad installed?

    Reset SMC.     http://support.apple.com/kb/HT3964
    Choose the method for:
    "Resetting SMC on portables with a battery you should not remove on your own".
    If this does not help, take the computer to the Apple store to have it checked out
    and repaired, if needed.
    Best.

  • IPOD DOES NOT FOLLOW FINGER ACTIONS IN DIFFERENT GAMES LIKE JELLY SPLASH

    transparant cover removed no significant improvement.
    ipod does not follow exactly my finger movement.
    this does not happen permanently some times the ipod works ok, somte times not.

    Make sure the screen is clean
    Try:
    - Reset the iOS device. Nothing will be lost      
    Reset iOS device: Hold down the On/Off button and the Home button at the same time for at
    least ten seconds, until the Apple logo appears.
    - Reset all settings                            
    Go to Settings > General > Reset and tap Reset All Settings.
    All your preferences and settings are reset. Information (such as contacts and calendars) and media (such as songs and videos) aren’t affected.
    - Restore from backup. See:                                               
    iOS: Back up and restore your iOS device with iCloud or iTunes
    - Restore to factory settings/new iOS device.                       
    If still problem, make an appointment at the Genius Bar of an Apple store since it appears you have a hardware problem.
      Apple Retail Store - Genius Bar                                              

  • I can not gain access to my gmail accounts because it is blocking thunderbird from getting my mail because Mozilla does not follow Industry Security Standards

    because it is blocking thunderbird from getting my mail because Mozilla does not follow Industry Security Standards

    Says who? Where are you getting this?
    I guess you believe the "Less Secure App" rubbish that gmail is putting out.
    Gmail has an option to allow these "less secure app" into their secure world.
    I also hear that the gmail world is flat. :)

  • Upper case "s" does not work in most programs

    Upper case "s" does not work in a number of programs, lower case is fine. It is the only letter that is missing in both cases.
    Any ideas. Do I need to reinstall driver for keyboard? If so any idea where to get it.

    Open the Speech pane of System Preferences and check whether either the listening key or the speech key has become set to that keystroke; if so, change the setting.
    (41135)

  • Webcan does not follow

    I have FG creative webcam live: motion cli fg2/2-23-00-00. When first installed and when first bring up computer it moves, after that it does not follow. Have to sit it up on things for others to see me. Also is there a stand you can buy for it's

    Open date and time preferences and make sure it is set to automatically.
    Reset PRAM:
    Turn on holding Command + Option + P + R until you hear the startup chime for the second time.

Maybe you are looking for

  • Error message when opening Encore

    Hi there.  I have been working with CS5 just fine for several weeks now and have burned several different projects without issues.  However, when I opened up Encore this morning to start building a DVD, I got this message: Adobe Encore.exe - No Disk.

  • Some newbie POWL feeder class questions

    Hi, I'm just working with POWLs resp. the associated feeder class. At the moment I have two question that hopefully could be answered by someone: 1) Is it possible to modify the UI layout of the selection criteria in a way that they will be displayed

  • Why can't i print wireless

    why can't i print wireless?

  • ABAP key word documentation  not appearing

    Hi every one when i press F1 on a keyword in ABAP editor it displaying ABAP keyword documentation with blank page. i am using vista OS and SAPGUI 6.0 and Internet explorer 7.0 Please suggest me what to do to get the Key word help. Most useful answer

  • Call a external SWF by press the button within another SWF file but the second SWF file play Externely

    Hello Guyz. i am working on Macromedia Flash 8 and i just want to call a external SWF when i press the button within another SWF file.......but the second SWF file play Externely............can any one knows the code.... AS2