Count of Weeks where a certain measure is 0

Hi,
I'm trying to create a calculated measure which would give me count of weeks where a certain measure say Sales is greater than 0. I have a hierarchy YEAR->QUARTER->MONTH->WEEK in time dimension DIMTIME. And I have used the expression COUNT(MYCUBE_ONHANDASSETS GT 0) to get the count. But this expression gets count of weeks from all the years instead of selected time periods. Lets say I have the measure MYCUBE_SALES greater than 0 at 2 weeks in Jan 2010, then the count should be 2 at level Jan 2010 in the hierarchy. But it shows 50 which is total weeks in year 2010 where MYCUBE_SALES is greater than 0.
Can anyone help me solving the issue ?
Thanks,
RK

You should be able to copy the data from your MYDWCUBE_AVG cube to COUNT_CUBE using OLAP DML.
First limit the dimensions to the appropriate leaf values, then assign. The ACROSS clause should list the partition template (if MYDWCUBE_AVG is partitioned) or the composite if it is not. I am approximating below.
LIMIT TIME TO TIME_LEVELREL 'MONTH'
LIMIT PRODUCT TO PRODUCT_LEVELREL 'SKU'
...other leaf level conditions
LIMIT COUNT_CUBE_MEASURE_DIM TO 'ONHANDASSETSCOUNT'
LIMIT MYDWCUBE_AVG_MEASURE_DIM TO 'ONHANDASSETS'
COUNT_CUBE_STORED = MYDWCUBE_AVG_STORED ACROSS MYDWCUBE_AVG_PRT_TEMPLATEIf you are in 11.2.0.2 then you can also use DBMS_CUBE to copy the data without needing to worry about the physical object details.
begin DBMS_CUBE.BUILD(q'! COUNT_CUBE USING
     FOR
        "TIME" LEVELS ("TIME"."MONTH"),
        "PRODUCT" LEVELS ("PRODUCT"."SKU"),
         ... other leaf level conditions ...
     BUILD
       SET COUNT_CUBE.OnHandAssetsCount = MYDWCUBE_AVG.OnHandAssets
end;
/

Similar Messages

  • Getting last-day-of-week dates within certain date range

    Hi all,
    I have the following Challenge:
    I want to know the dates of the last day of all the weeks within a certain range of dates.
    For instance if my range would be 01-jun-2002 - 31-jun-2002
    then the returned days should be (lastday of the week is sunday):
    . 02-jun-2002
    . 09-jun-2002
    . 16-jun-2002
    . 23-jun-2002
    . 30-jun-2002
    I want to accomplish this by only using sql (no pl/sql) in a ora 8.0.x rdbms
    How would I do this? (if it's possible)
    Tia,
    Martin

    Christian's solution returns
    01-JUN-02
    08-JUN-02
    15-JUN-02
    22-JUN-02
    on my system. The first day of the week is dependent on NLS settings.
    SELECT MAX(realdate)
    FROM (
    SELECT TO_CHAR(TO_DATE('31-may-2002','dd-mon-yyyy') + ROWNUM,'IW') weekno,
           TO_DATE('31-may-2002','dd-mon-yyyy') + ROWNUM realdate
    FROM all_objects
    WHERE rownum <= TO_DATE('30-Jun-2002','dd-mon-yyyy') - TO_DATE('01-Jun-2002','dd-mon-yyyy')
    GROUP BY weeknoThe IW format model give ISO standard week numbers and a week always starts on Monday.

  • Word Count, but only words over certain number of letter...?

    Hi,
    Does anyone know of a way to do a word count, but only count the words with a certain number of letters. For example all words with 4 letters or more?
    Thanks

    I never guessed that I will read such a question but why not ?
    --(SCRIPT word4Count.app]
    --==========
    Enregistrer le script en tant qu'Application ou Progiciel : word4count.app
    déplacer l'application créée dans le dossier
    <VolumeDeDémarrage>:Users:<votreCompte>:Library:Scripts:Applications:Pages:
    Il vous faudra peut-être créer le dossier Pages et même le dossier Applications.
    menu Scripts > Pages > word4count
    Le script affiche (ou insère à l'emplacement du curseur )
    le nombre de mots de la couche texte et
    le nombre de mots des blocs texte
    dont la longueur est supérieure à la valeur définie par la property limite.
    --=====
    L'aide du Finder explique:
    L'Utilitaire AppleScript permet d'activer le Menu des scripts :
    Ouvrez l'Utilitaire AppleScript situé dans le dossier Applications/AppleScript.
    Cochez la case "Afficher le menu des scripts dans la barre de menus".
    --=====
    Grace au programme gratuit ThisService, il est possible d'encapsuler ce script dans un service.
    Télécharger ThisService depuis:
    http://wafflesoftware.net/thisservice/
    Lors de la création du service, cliquer le bouton "Produce output".
    Il est possible d'associer un raccourci clavier au service.
    --==========
    Copy the script in the clipboard
    Paste in a blank window of Script Editor
    Save it as an Application or an Application Bundle
    Move the newly created application into the folder:
    <startup Volume>:Users:<yourAccount>:Library:Scripts:Applications:Pages:
    Now, enter your Pages document.
    Click where you want.
    Go to
    menu Scripts > Pages > word4count
    The script will count the words whose length is higher than the value stored in the property limite.
    The wordcount will be pasted at the insertion point
    --=====
    The Finder's Help explains:
    To make the Script menu appear:
    Open the AppleScript utility located in Applications/AppleScript.
    Select the "Show Script Menu in menu bar" checkbox.
    --=====
    Thanks to the free program ThisService, we may encapsulate this script in a Service.
    Download ThisService from
    http://wafflesoftware.net/thisservice/
    When creating the service click the button "Produce output"
    We may link the service to a shortcut.
    --==========
    Yvan KOENIG
    19 février 2009
    --=====
    property limite : 4
    property affiche : true
    --=====
    property theApp : "Pages"
    property ws : {}
    --=====
    on process()
    set rezult to my commun()
    tell application "System Events"
    activate
    display dialog rezult
    end tell
    return ""
    end process
    --=====
    on commun()
    local liste1, liste2, ng, c1, c2
    --set my ws to {}
    tell application "Pages" to tell document 1
    set liste1 to words of body text
    set liste2 to {}
    set ng to count of graphic
    repeat with i from 1 to ng
    tell graphic i
    try
    copy items of (get words of object text) to end of liste2
    end try
    end tell -- graphic i
    end repeat
    (* Working this way we are counting the words as they are defined by Pages *)
    end tell -- document 1 of Pages
    if liste1 is not {} then
    set my ws to liste1
    set c1 to my compte4()
    else
    set c1 to 0
    end if
    if liste2 is not {} then
    set my ws to liste2
    set c2 to my compte4()
    else
    set c2 to 0
    end if
    set my ws to {}
    if my parlefrancais() then
    return "Nombre de mots dont la longueur dépasse " & limite & return & "dans la couche texte : " & c1 & return & "dans des blocs : " & c2
    else
    return "Count of words whose length is greater than " & limite & return & "in text layer : " & c1 & return & "in text blocks : " & c2
    end if
    end commun
    --=====
    on compte4()
    local wc, w
    set wc to 0
    repeat with w in my ws
    if length of (w as text) > limite then set wc to wc + 1
    end repeat
    return wc
    end compte4
    --=====
    on parlefrancais()
    local z
    try
    tell application theApp to set z to localized string "Cancel"
    on error
    set z to "Cancel"
    end try
    return (z = "Annuler")
    end parlefrancais
    --=====
    on run
    set rezult to my commun()
    if affiche then (*
    display the results *)
    tell application theApp to display dialog rezult
    else (*
    insert the results in the text body *)
    tell application "Pages" to tell document 1 to set selection to rezult
    end if
    end run
    --=====
    --[/SCRIPT]
    Yvan KOENIG (from FRANCE jeudi 19 février 2009 15:45:56)

  • Finding out where a certain colour is used

    Hi everyone,
    is there a way to find out where a certain colour (swatch) is used inside a document, like on what page or something?
    Inside a single-page document is not a big deal, in a 200+ paged document it is hell to find out…
    I can search for "character colour" and search again for object fill and again for stroke and again and again.
    I'm looking for an "easy" way to use.
    or maybe there is a script for that?
    thanks for helping me out!

    jocstone_me wrote:
    Hi everyone,
    is there a way to find out where a certain colour (swatch) is used inside a document, like on what page or something?
    Inside a single-page document is not a big deal, in a 200+ paged document it is hell to find out…
    I can search for "character colour" and search again for object fill and again for stroke and again and again.
    I'm looking for an "easy" way to use.
    or maybe there is a script for that?
    thanks for helping me out!
    The commercial Blatner Tools plug-in for InDesign from dtptools.com can find colors and can create a report of all colors or only those used in the current document. There's a 14-day free trial.
    I have no connection to the company other than being a satisfied user.
    HTH
    Regards,
    Peter
    Peter Gold
    KnowHow ProServices

  • Where is the measuring tool in Acrobat XI?

    Where is the measuring tool in Acrobat XI?

    yes i just found it. I had to get rid of the common tools box and go to view then tool sets. Thanks for the response.

  • Is there a way to get to a certain measure without having to scroll the line thing all the way there if our file is hours long?

    Is there a way to get to a certain measure without having to scroll the line thing all the way there if our file is hours long?

    CNWSMT wrote:
    Is there a way to get to a certain measure without having to scroll the line thing all the way there if our file is hours long?
    double click the measures display (the LCD) and type in the measure

  • Retrieving the row number where a certain value exists

    Hi,
    I wanted to find out if there is a way to retrieve the row number of a row where a certain value exists. For example, if I had a query
    Create or replace Procedure p1
    IS
    v_Stmt varchar2(100);
    BEGIN
    v_Stmt := 'Select * from emp where lname = 'Davis'';
    Execute Immediate v_Stmt;
    END;
    SQL> exec p1;
    Then, I would like to find out that this name is on row 3.
    Can anyone tell me how this can be done?
    Thanks in advance.
    Sincerely,
    Nikhil Kulkarni

    theres is no rownum related to a particular row. A rownum is a pseudocolumn which value may be different for the same row depending on the query you do. What you can use is the rowid which is the row's address.
    HTH
    Maurice

  • Most efficient way to get row count with a where clause

    Have not found a definitive answer on how to do this.  Is there a better way to get a row count from a large table that needs to satisfy a where clause like so:
    SELECT COUNT(*) FROM BigTable WHERE TypeName = 'ABC'
    I have seen several posts suggesting something like 
    SELECT COUNT(*) FROM BigTable(NOLOCK);
    and 
    selectOBJECT_NAME(object_id),row_count from sys.dm_db_partition_stats
    whereOBJECT_NAME(object_id)='BigTable'but I need the row count that satisfies my where clause (i.e.: WHERE TypeName = 'ABC')

    It needs index to improve the performance. 
    - create index on typename column
    - create a indexed view to do the count in advance
    -partition on type name (although it's unlikely) then get count from the system tables...
    all those 3 solutions are about indexing.
    Regards
    John Huang, MVP-SQL, MCM-SQL, http://www.sqlnotes.info

  • Are there any issues with itunes where as certain windows looks like a PC in safe mode?

    are there any issues with itunes where as certain windows looks like a PC in safe mode?

    Check your trash. I had some old uninstalled files in there. Deleted and restated itunes. seems to work.

  • Count before and after to certain occurance.

    I am trying to count the amount of units  studied before and after a certain Course was taken.
    So ID 1 did PREP in 2013 in the first period and has and also had done a unit in 2009 so reult be before prerp count 1
    ID 2 did PREP in 2012 first period and also an OTHER course in the same period as well as a OTHER in period 2. So when a PREP course appear in the same period and year as an OTHER course I would like it to count it as AFTER Prep.(see below(so when equal count as after PREP))
    ID 3 has done one unit before before PREP which is in 2011 and 2 Units after the first PREP course.
    I attepted this with not in and in statments basic I know but to no luck.
    Any help is greatly appreciated.
    Thanks
    CREATE TABLE DAN_DIRK_2
    (ID     VARCHAR2(8),
    YEAR    VARCHAR2(8),
    PERIOD VARCHAR2(8),
    COURSE VARCHAR2(12),
    UNIT VARCHAR2(12));
    INSERT INTO DAN_DIRK_2 (ID, YEAR,PERIOD,COURSE,UNIT) VALUES (1,'2013','SP1','PREP','PLI');
    INSERT INTO DAN_DIRK_2 (ID, YEAR,PERIOD,COURSE,UNIT) VALUES (1,'2009','SP4','OTHER','DRI');
    INSERT INTO DAN_DIRK_2 (ID, YEAR,PERIOD,COURSE,UNIT) VALUES (2,'2012','SP1','OTHER','FER');
    INSERT INTO DAN_DIRK_2 (ID, YEAR,PERIOD,COURSE,UNIT) VALUES (2,'2012','SP2','OTHER','AQW');
    INSERT INTO DAN_DIRK_2 (ID, YEAR,PERIOD,COURSE,UNIT) VALUES (2,'2012','SP1','PREP','FGV');
    INSERT INTO DAN_DIRK_2 (ID, YEAR,PERIOD,COURSE,UNIT) VALUES (3,'2011','SP1','OTHER','GVW');
    INSERT INTO DAN_DIRK_2 (ID, YEAR,PERIOD,COURSE,UNIT) VALUES (3,'2012','SP2','PREP','FER');
    INSERT INTO DAN_DIRK_2 (ID, YEAR,PERIOD,COURSE,UNIT) VALUES (3,'2013','SP1','OTHER','FSW');
    INSERT INTO DAN_DIRK_2 (ID, YEAR,PERIOD,COURSE,UNIT) VALUES (3,'2013','SP1','PREP','FGH');
    GIVES:
    ID
    YEAR
    PERIOD
    COURSE
    UNIT
    1
    2013
    SP1
    PREP
    PLI
    1
    2009
    SP4
    OTHER
    DRI
    2
    2012
    SP1
    OTHER
    FER
    2
    2012
    SP2
    OTHER
    AQW
    2
    2012
    SP1
    PREP
    FGV
    3
    2011
    SP1
    OTHER
    GVW
    3
    2012
    SP2
    PREP
    FFR
    3
    2013
    SP1
    OTHER
    FSW
    3
    2013
    SP1
    PREP
    FGH
    WANT:
    ID
    BEFORE
    AFTER
    1
    1
    0
    2
    0
    2
    3
    1
    2

    Chloe_19 wrote:
    Get an Error
    ORA-32033: unsupported column aliasing
    32033. 00000 -  "unsupported column aliasing"
    *Cause:    column aliasing in WITH clause is not supported yet
    *Action:   specify aliasing in defintion subquery and retry
    Error at Line: 1 Column: 8
    Am using version:
    Oracle Database 10g Enterprise Edition Release 10.2.0.5.0 - 64bi
    because you use 10g, try this :
    WITH tt AS (
    select 1 ID,  2013 YR,  'SP1' PERIOD,  'PREP' COURSE,  'PLI' UNIT from dual union all
    select 1,  2009,  'SP4',  'OTHER',  'DRI' from dual union all
    select 2,  2012,  'SP1',  'OTHER',  'FER' from dual union all
    select 2,  2012,  'SP2',  'OTHER',  'AQW' from dual union all
    select 2,  2012,  'SP1',  'PREP',  'FGV' from dual union all
    select 3,  2011,  'SP1',  'OTHER',  'GVW' from dual union all
    select 3,  2012,  'SP2',  'PREP',  'FFR' from dual union all
    select 3,  2013,  'SP1',  'OTHER',  'FSW' from dual union all
    select 3,  2013,  'SP1',  'PREP',  'FGH' from dual ),
    tt2 AS (
    SELECT t.ID,
           min(t.YR) minyr, 
           min(replace(t.PERIOD,'SP','')) KEEP(DENSE_RANK FIRST ORDER BY T.YR) minpr
    FROM  tt t
    WHERE t.COURSE = 'PREP'
    GROUP BY t.ID)
        SELECT ID,
               NVL(COUNT(BEF),0) BEFORE,
               NVL(COUNT(AFT),0) AFTER
               FROM(          
                        SELECT t1.ID,
                               (CASE WHEN t1.YR = t2.minyr AND replace(t1.PERIOD,'SP','')= t2.minpr AND t1.course='PREP' THEN NULL
                                     WHEN t1.YR = t2.minyr AND replace(t1.PERIOD,'SP','')= t2.minpr AND t1.course!='PREP' THEN NULL
                                     WHEN t1.YR < t2.minyr THEN -1
                                     WHEN t1.YR = t2.minyr AND replace(t1.PERIOD,'SP','')<= t2.minpr THEN -1
                                 END) BEF,
                               (CASE WHEN t1.YR = t2.minyr AND replace(t1.PERIOD,'SP','')= t2.minpr AND t1.course='PREP' THEN NULL
                                     WHEN t1.YR = t2.minyr AND replace(t1.PERIOD,'SP','')= t2.minpr AND t1.course!='PREP' THEN 1
                                     WHEN t1.YR > t2.minyr THEN 1
                                     WHEN t1.YR = t2.minyr AND replace(t1.PERIOD,'SP','')>= t2.minpr THEN 1
                                 END) AFT        
                         FROM tt t1
                        LEFT JOIN tt2 t2
                               ON t2.id = t1.id
        GROUP BY ID
        ORDER BY 1

  • Total open tasks count by week

    Hello,
    I was wondering if someone is able and willing to help me with a code to calculate something in MS SQL server (me being at the start of learning SQL myself).
    I apologize in advance if this is not the section I should post on, or the type of question you people care about :)
    I have a table that among other information, it would contain:
    TaskID
    DateCreated (the date each task was created)
    Date Closed (the date each task was closed, if closed yet)
    Week_Of (this is also a date format and it represents the fiscal week that the 'DateCreated' is part of; for example Week_Of 30-Nov-2014 is linked to 30-Nov-2014 to 06-Dec-2014 dates).
    I want to show the number of tasks that are still open at the end of each 'Week_Of'. So for 'Week_Of' valued 30-nov-2014, I need a count of all tasks submitted by 06-Dec-2014 (Week_Of+6) that were either not closed at this date (DateClosed NULL) or were
    closed on a more recent date.
    This calculation to be done for each value of 'Week_Of' in the table (so, across several fiscal years).
    Each week new tasks are created (that would also have to be counted on the next 'Week_Of' calculation) and some of the existent tasks are closed (which of course, should not be counted anymore for the next 'Week_Of' calculation).
    Thanks.

    DO you mean this?
    SELECT ProjectID,ProjectType,WeekOf,COALESCE(Cnt,0) AS OpenTasks
    FROM
    SELECT DISTINCT ProjectID,ProjectType,WeekOf,DATEADD(dd,(DATEDIFF(dd,0,DateCreated)/7) * 7,5) AS EndDate
    FROM Table
    )t
    OUTER APPLY(SELECT COUNT(*) AS Cnt
    FROM Table
    WHERE ProjectID = t.ProjectID
    AND ProjectType = t.ProjectType
    AND CASE WHEN DateCreated > EndDate OR DateClosed < EndDate - 6 THEN 0 ELSE 1 END = 1
    )u
    Please Mark This As Answer if it solved your issue
    Please Vote This As Helpful if it helps to solve your issue
    Visakh
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • Count consecutive Workdays where employee has taken SICK leave

    I am trying to identify a way within sql to count the number of consecutive workdays (Monday - Friday) an employee has taken SICK leave. My problem in the past has been trying to count days whereas we cross the weekend. Currently I have 4 queries identifying patterns around the weekend that I run and export into an Excel Spreadsheet and manipulate from there. My goal is to be able to list an EMPLID (employee id), EMPL_RCD ( employee record), Min(DUR) (Date of absence), Max(DUR), and count of consecutive workdays.
    Any help or guidance would will be appreciated. I have attached my current query.
    I run my current query 4 times using the patterns below one at a time.
    SELECT DISTINCT A.EMPLID,A.EMPL_RCD, A.DUR,b.dur,c.dur,d.dur, A.TL_QUANTITY, A.TRC
    FROM PS_TL_RPTD_TIME A, PS_TL_RPTD_TIME B, PS_TL_RPTD_TIME C,PS_TL_RPTD_TIME D
    WHERE A.EMPLID = B.EMPLID
    AND A.EMPL_RCD = B.EMPL_RCD
    AND A.EMPLID = C.EMPLID
    AND A.EMPL_RCD = C.EMPL_RCD
    AND A.EMPLID = D.EMPLID
    AND A.EMPL_RCD = D.EMPL_RCD
    AND B.EMPLID = C.EMPLID
    AND B.EMPL_RCD = C.EMPL_RCD
    AND B.TRC = C.TRC
    AND A.TRC = B.TRC
    AND A.TRC = C.TRC
    AND A.TRC = D.TRC
    AND (B.DUR = A.DUR+3 AND C.DUR = A.DUR+4 AND D.DUR = A.DUR+5) Friday, Monday, Tuesday, Wednesday
    AND (B.DUR = A.DUR+1 AND C.DUR = A.DUR+4 AND D.DUR = A.DUR+5) Thursday, Friday, Monday, Tuesday
    AND (B.DUR = A.DUR+1 AND C.DUR = A.DUR+2 AND D.DUR = A.DUR+5) Wednesday, Thursday, Friday, Monday
    AND (B.DUR = A.DUR+1 AND C.DUR = A.DUR+2 AND D.DUR = A.DUR+3) -- Same workweek
    AND A.TRC LIKE 'SICK%'
    AND NOT EXISTS ( SELECT 'x' FROM PS_JOB J
    WHERE J.EMPLID = A.EMPLID
    AND J.EMPL_RCD = A.EMPL_RCD
    AND J.EMPL_STATUS IN ('P','L')
    AND J.EFFDT = ( SELECT MAX(J1.EFFDT) FROM PS_JOB J1
    WHERE J1.EMPLID = J.EMPLID
    AND J1.EMPL_RCD = J.EMPL_RCD
    AND J1.EFFDT <= D.DUR))

    You should consider a technique from data warehousing where you use a table to describe dates. To keep things simple, let's create a table that holds all your valid business days for the past 2 weeks...
    create table business_dates (business_day date);
    begin
    insert into business_dates values (to_date('16-oct-2006'));
    insert into business_dates values (to_date('17-oct-2006'));
    insert into business_dates values (to_date('18-oct-2006'));
    insert into business_dates values (to_date('19-oct-2006'));
    insert into business_dates values (to_date('20-oct-2006'));
    insert into business_dates values (to_date('23-oct-2006'));
    insert into business_dates values (to_date('24-oct-2006'));
    insert into business_dates values (to_date('25-oct-2006'));
    insert into business_dates values (to_date('26-oct-2006'));
    insert into business_dates values (to_date('27-oct-2006'));
    insert into business_dates values (to_date('30-oct-2006'));
    insert into business_dates values (to_date('31-oct-2006'));
    insert into business_dates values (to_date('01-nov-2006'));
    insert into business_dates values (to_date('02-nov-2006'));
    insert into business_dates values (to_date('03-nov-2006'));
    end;
    now we create a table that shows whether each employee was sick or not for a given work day...
    create table attendance (empid number, business_day date, sick char(1));
    insert into attendance values (100, to_date('16-oct-2006'), 'N');
    insert into attendance values (100, to_date('17-oct-2006'), 'Y');
    insert into attendance values (100, to_date('18-oct-2006'), 'Y');
    insert into attendance values (100, to_date('19-oct-2006'), 'N');
    insert into attendance values (100, to_date('20-oct-2006'), 'N');
    insert into attendance values (100, to_date('23-oct-2006'), 'Y');
    insert into attendance values (100, to_date('24-oct-2006'), 'Y');
    insert into attendance values (100, to_date('25-oct-2006'), 'Y');
    insert into attendance values (100, to_date('26-oct-2006'), 'N');
    insert into attendance values (100, to_date('27-oct-2006'), 'N');
    insert into attendance values (100, to_date('30-oct-2006'), 'N');
    insert into attendance values (100, to_date('31-oct-2006'), 'Y');
    insert into attendance values (100, to_date('01-nov-2006'), 'N');
    insert into attendance values (100, to_date('02-nov-2006'), 'N');
    insert into attendance values (100, to_date('03-nov-2006'), 'N');
    insert into attendance values (105, to_date('16-oct-2006'), 'Y');
    insert into attendance values (105, to_date('17-oct-2006'), 'Y');
    insert into attendance values (105, to_date('18-oct-2006'), 'N');
    insert into attendance values (105, to_date('19-oct-2006'), 'N');
    insert into attendance values (105, to_date('20-oct-2006'), 'Y');
    insert into attendance values (105, to_date('23-oct-2006'), 'N');
    insert into attendance values (105, to_date('24-oct-2006'), 'N');
    insert into attendance values (105, to_date('25-oct-2006'), 'Y');
    insert into attendance values (105, to_date('26-oct-2006'), 'Y');
    insert into attendance values (105, to_date('27-oct-2006'), 'Y');
    insert into attendance values (105, to_date('30-oct-2006'), 'Y');
    insert into attendance values (105, to_date('31-oct-2006'), 'Y');
    insert into attendance values (105, to_date('01-nov-2006'), 'N');
    insert into attendance values (105, to_date('02-nov-2006'), 'N');
    insert into attendance values (105, to_date('03-nov-2006'), 'Y');
    Now the query to get each sick occurrence and the number of consecutive days for each employee is...
    select empid, first_sick_day, sick_count from
    (select empid,
    first_value(business_day) over (partition by empid, groupno order by business_day) as first_sick_day,
         row_number() over (partition by empid, groupno order by business_day) as rn,
    count(*) over (partition by empid, groupno) as sick_count
    from
    (select empid, business_day, daynum-rownum groupno
         from
              (SELECT a.empid, a.business_day, d.day_num as daynum
                   FROM attendance a,
                        (select rownum as day_num, business_day
                        from (select business_day from business_dates order by business_day)) d
                   WHERE sick = 'Y' AND a.business_day = d.business_day
                   ORDER BY 1,2 )
    where rn = 1;
    The above query can be modified slightly to only give you the sick occurrence with the maximum number of consecutive days for each employee.
    Having a separate date table is nice because you can take in account weekends, holidays or any other nonwork day by just removing that date from the table. Generating this table is easy as date dimension examples can be found on on the web, and the amount of rows is small (250 rows per year approx).
    JR

  • How to find total row count on weekly basis

    I have written a join query which works perfect and it give me total number of rows between two dates, however is there a way where i can modify my query so that i can see the result on weekly basis from January 2014 to may 2014
    ;WITH SourceData
    as
        SELECT tablet.Approach.ApproachId
        ,StartDateTime
        ,QuestionId, Stage
        FROM Tablet.Approach
        JOIN tablet.DataCapture ON tablet.Approach.ApproachId = tablet.DataCapture.ApproachId
        WHERE QuestionId in (9,10)
        and Stage = 2
        and StartDateTime between '2014-01-01 00:00:00' and '2014-05-20 00:00:00'
    ,RecordCnt
    AS
        SELECT COUNT(ApproachId) AS TotalInformationEffectContacts
        FROM SourceData
    Select * from SourceData Cross join RecordCnt
    order by StartDateTime asc

    Use GROUP BY datediff(ww,@startdate,@enddate)
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

  • Is there a way to find out how many steps you walked on a specific day in the Apple Health App.  I don't want to know minute by minute.  But want to know if I can go back a week to a certain day.

    LF way to see how many steps I walked on a certain day last week.  Not minute by minute, just recall the day's steps.  All I get is a graph and then all data when I tap a particular day,  which is far too detailed and useless.

    here is a link to macosxhints.com that tells you how to output all of your feed URLs to a terminal window. from there you can cut and paste them into your new feed reader of choice...
    http://www.macosxhints.com/article.php?story=20080319094830396
    and if you are in the marked for a new reader may i suggest David Watanabe's excellent NewsFire. he had just recently made it totally free as a gift to the macintosh community.
    best of luck.

  • Calculating a count of rows where value matches another column value in the same table

    Hi,
    I'm struggling to do something in DAX that seems to me should be super easy (coming from a SQL world)!
    That is to count all rows in column 1 where the value matches the current value for column 1?
    E.g something like this:
    [Col2]=Count of rows in [Col1] where value = this.[Col1]
    Where the results are as in the table below:
    Col1, Col2
    A, 2
    A, 2
    B, 1
    Anyone?
    Martin Laukkanen
    Nearbaseline blog - nearbaseline.com/blog
    Bulk Edit and other Apps - nearbaseline.com/apps

    Thanks, that's perfect! 
    I knew it had to be something so simple, but after spending over an hour banging my head against those exact functions I couldn't get anything working!
    Martin Laukkanen
    Nearbaseline blog - nearbaseline.com/blog
    Bulk Edit and other Apps - nearbaseline.com/apps

Maybe you are looking for