Distinct Count Help

Okay I have 3 fields for call records : On call & Daily Assignment to indicate the service level when the call came in. The 3rd field displays the assignment duration of the call in HH:MM:
I need to find a way to show the count of the calls where
A-  Count of on call records that exceed 4 hours (assignment duration) compared to all on call records
B - Count of daily assignment records that exceed 2 hours (assignment duration) compared to all daily assignment records

Hi Willie,
I guess this is in continuation to this thread:
If Statements
Here's what you need to do:
1) Create this formula and place it on the Details Section:
If {@Name_of_formula} = "On Call" then
     If DateDiff("s", {Assignment_Datetime}, {Resolved_Datetime}) > 14400 then 1
Replace {@Name_of_formula} with the formula that displays 'On call' and 'Daily Assignment'.
2) Go to Insert Summary > Choose the above formula field as the 'Field to Summarize' > Choose 'Sum' as the Summary Operation > Choose the 'Summary Location' as 'Report Footer'.
You can then drag this summary to the Report Header as well if you wish to.
This is the Count for all 'On call' records that exceed 4 hours.
3) To get the count for 'Daily Assignment', create this formula:
If {@Name_of_formula} = "Daily Assignment" then
     If DateDiff("s", {Assignment_Datetime}, {Resolved_Datetime}) > 7200 then 1
4) Repeat Step 2 and this time choose this formula field as the field to summarize.
Hope this helps.
-Abhilash

Similar Messages

  • Absolute Distinct count in Array -----Please help me out

    I'm running out of time and i have no clues to solve it.......can you please help me on it....
    The Absolute Distinct Count on Sorted Array is the count of
    distinct absolute values of elements of the array.
    For example, for the array.
    *[-5, -3, -1, 0, 3, 6]*
    the absolute distinct count is 5, because there is 5 distinct
    absolute values:
    *0, 1, 3, 5, 6*
    Write a function that computes the absolute distinct count
    of a given array.

    No, above code wouldn't work. Though it will give distinct count, but not absolute distinct count.
    Code to get absolute distinct count of elements in an array:
         public static void main(String args[]){
              int[] values = { -5, -3, -1, 0, 3, 6 };
              List<Integer> list=new ArrayList<Integer>();
              int tempVal=0;
              for(int val : values){
                   tempVal=Math.abs(val);
                   if(!list.contains(tempVal)){
                        list.add(tempVal);
              System.out.println("Absolute distinct count: "+list.size());
              System.out.println("Absolute distinct elements: "+list.toString());                    
         }Thanks,
    Mrityunjoy

  • How to get Distinct Count of Products across two dimensions

    Hi,
    I have two dimensions, Item and Presentations. I need to get distinct count of products for IMD_Id + Merc_Pres_Id. IMD_Id is the lowest member in Item and Merc_Pres_Id is lowest in Presentation. My MDX query is given below but when I apply filters to
    slice it, it does not work and does not give right count. It always gives the count for all.
    /* Last Year Demand - Demand for 12 months back of selected months */
    With
    Member [Measures].[LYDemand]
    as
    Sum(
    Generate(
    EXISTING[All Date].[Fiscal Month Name].[Fiscal Month Name].Members,
    {parallelperiod([All Date].[Fiscal Month Name].[Fiscal Month Name], 12
    ,[All Date].[Fiscal Month Name].CurrentMember)}
    ,[Measures].[Proj Demand]
    /* Last to last Year Demand - Demand for 24 back of selected months */
    Member [Measures].[LLYDemand]
    as
    Sum(
    Generate(
    EXISTING[All Date].[Fiscal Month Name].[Fiscal Month Name].Members,
    {parallelperiod([All Date].[Fiscal Month Name].[Fiscal Month Name], 24
    ,[All Date].[Fiscal Month Name].CurrentMember)}
    ,[Measures].[Proj Demand]
    /* Current Year Active Products */
    Member [Measures].[CYCount]
    as
    CASE
    WHEN
    [Measures].[Proj Demand] > 0
    THEN
    DistinctCount(Existing(([All Items].[IMD Id].[IMD Id],[All Merchandise Presentations].[Merch
    Pres Key].[Merch Pres Key])))
    ELSE
    NULL
    END
    /* Last year Active Products */
    Member [Measures].[LYCount]
    as
    CASE
    WHEN
    [Measures].[LYDemand] > 0
    THEN
    DistinctCount(([All Items].[IMD Id].[IMD Id],[All Merchandise Presentations].[Merch Pres Key].[Merch Pres
    Key], [All Items].[Style Name].CurrentMember, (StrToMember('[All Date].[Fiscal Month Name].&[201401]',CONSTRAINED).Lag(12)
    : StrToMember('[All Date].[Fiscal Month Name].&[201411]',CONSTRAINED).Lag(12))))
    ELSE
    NULL
    END
    /* Last to last Year Active Products */
    Member [Measures].[LLYCount]
    as
    CASE
    WHEN
    [Measures].[LLYDemand] > 0
    THEN
    DistinctCount(([All Items].[IMD Id].[IMD Id],[All Merchandise Presentations].[Merch Pres Key].[Merch Pres
    Key], [All Items].[Style Name].CurrentMember, (StrToMember('[All Date].[Fiscal Month Name].&[201401]',CONSTRAINED).Lag(24)
    : StrToMember('[All Date].[Fiscal Month Name].&[201411]',CONSTRAINED).Lag(24))))
    ELSE NULL END
    SELECT
    [Measures].[CYCount], [Measures].[LYCount], [Measures].[LLYCount],
    [Measures].[Proj Demand],[Measures].[LYDemand],[Measures].[LLYDemand]
    ON
    COLUMNS,
    Non
    Empty([All Items].[Demand Center Name].[Demand Center Name], [All Items].[Style Name].[Style Name])
    ON ROWS
    FROM
    (SELECT (StrToSet('[All Items].[Style].[ALL]'))
    ON COLUMNS
    FROM
    (SELECT (StrToSet('[All Items].[Demand Center].[ALL]'))
    ON COLUMNS
    FROM
    (select (STRTOSET('[All Items].[Merch Group].&[MG-110]'))
    on Columns
    FROM
    (SELECT (StrToSet('[All Merchandise Presentations].[Merch Pres Chnl Dkey].&[MPC-1]'))
    ON COLUMNS
    From
    [FMI Forecasting]
    WHERE {strToMember('[All Date].[Fiscal Month
    Name].&[201401]',CONSTRAINED) :
    StrToMember('[All Date].[Fiscal Month Name].&[201411]',CONSTRAINED)}
    Requirements are as follows:
    1. Distinct Count should not include products where Proj Demand is 0, when I am using Filter function to remove products with 0 demand, query is really slow and execution time goes up from 35- 40 secs to 8-9 Minutes.
    2. When we apply filter (parameters) Distinct Count should be in the context of filters( which are mentioned in the select statement like Style, Demand Center and Merch Group). Currently after applying filters count does not change.
    Thanks for help.

    Hi Skd78,
    Thank you for your question. 
    I am trying to involve someone more familiar with this topic for a further look at this issue. Sometime delay might be expected from the job transferring. Your patience is greatly appreciated. 
    Thank you for your understanding and support.
    Regards,
    Charlie Liao
    TechNet Community Support

  • How do I solve this distinct count problem?

    Hello experts,
      So, I have an OBI report (table view).  I needed to get the percentage difference btn 2 columns, I did. Then I had to summarize difference in 4 buckets (0-15, 16-30, 31-50, >50%); I did (case statement). NOW,  I need to summarize(distinct count) the above buckets based on Store numbers for each day.
    Basically, if the difference is btn(0-5%) and I have 5 stores then I need to see 5 stores separately. The problem I am having when I do the distinct count instead of having separate counts for each bucket I am getting the total.  I see the buckets summarized, but the store column is showing the total number of all(we have about 700 stores) instead of breaking down the count for each bucket.  In the stores column I am using the distinct count function, I don't know if the problem is here or the case statement for buckets. I don't know either OBIEE is able to do what I trying to do, since I have yet to do this kind of function.  I have gotten few leads on my first post,  so far none of them have worked.
    As always, your insights are highly appreciated,

    Instead of using Distinct Count in Aggregation Rule,Try using in Column Formula.
    Let me know if u need any help on this.
    Thanks,

  • Distinct count of dimension business key in fact table

    In my cube I have a fact table which joins to a patient dimension.  The patient dimension is a type 2.  What I would like to do is get a distinct count of patients who have records in the fact table.   The business key in the patient dimension
    is the PrimaryMrn.  So a SQL query would look like this.
    SELECT count(distinct PrimaryMrn)
    FROM EncounterFact e
    INNER JOIN PatientDim p
    on e.PatientKey = p.PatientKey
    Is it possible to do this via MDX?
    Thanks for the help.

    If you have to distinct count an attribute in a SCD 2, you might choose between:
    Denormalizing that attribute in the fact table, and the create a classical DISTINCT COUNT measure
    Use a many-to-many approach - see the "Distinct Count" scenario in the Many-to-Many White paper here:
    http://www.sqlbi.com/articles/many2many (for both Multidimensional and Tabular
    If you use Tabular, you might want to read also this pattern:
    http://www.daxpatterns.com/distinct-count/
    Marco Russo http://www.sqlbi.com http://www.powerpivotworkshop.com http://sqlblog.com/blogs/marco_russo

  • Distinct count for multiple fact tables in the same cube

    I'm fairly new to working with SSAS, but have been working with DW environments for many years.
    I have a cube which has 4 fact tables.  The central fact table is Encounter and then I also have Visit, Procedure and Medication.  Visit, Procedure and Medication all join to Encounter on Encounter Key.  The relationship between Encounter
    and Procedure and Encounter and Medication are both an optional 1 to 1.  The relationship between Encounter and Visit is an optional 1 to many.
    Each of the fact tables join to the Patient dimension on the Patient Key.  The users are looking for a distinct count of patients in all 4 fact tables.  
    What is the best way to accomplish this so that my cube does not talk all day to process?  Please let me know if you need any more information about my cube in order to answer this.
    Thanks for the help,
    Andy

    Hi Andy,
    Each distinct count measure cause an ORDER BY clause in the SELECT sent to the relational data source during processing. In SSAS 2005 or later, it creates a new measure group for each distinct count measure(it's a technique strategy for improving perormance).
    Besides, please take a look at the following distinct count optimization techniques:
    Create Customized Aggregations
    Define a Processing Plan
    Create Partitions of Equal Size
    Use Partitions Comprised of a Distinct Range of Integers
    Distribute the Hash of Your UserIDs
    Modulo Function
    Hash Function
    Choose a Partitioning Strategy
    For more detail information, please refer to the article below:
    Analysis Services Distinct Count Optimization:
    http://www.microsoft.com/en-us/download/details.aspx?id=891
    In addition, here is a good article about SSAS Best Practices for your reference:
    http://technet.microsoft.com/en-us/library/cc966525.aspx
    If you have any feedback on our support, please click
    here.
    Hope this helps.
    Elvis Long
    TechNet Community Support

  • Distinct Count doesn't return the expected results

    Hi All,
    I was fighting a little trying to implement a Distinct Count measure over an account dimension in my cube. I read a couple of posts relateed to that and I followed the steps posted by the experts.
    I could process the cube but the results I'm getting are not correct. The cube is returning a higher value compared to the correct one calculated directly from the fact table.
    Here are the details:
    Query of my fact table:
    select distinct cxd_account_id,
              contactable_email_flag,
              case when recency_date>current_date-365 then '0-12' else '13-24' end RECENCY_DATE_ROLLUP,
              1 QTY_ACCNT
    from cx_bi_reporting.cxd_contacts
    where cxd_account_id<>-1 and recency_date >current_date-730;
    I have the following dimensions:
         Account (with 3 different hierarchies)
         Contactable Email Flag (Just 3 values, Y, N, Unknown)
         Recency_date (Just dimension members)
    All dimensions are sparse and the cube is a compressed one. I defined "MAXIMUM" as aggregate for Contactable Email flag and Recency date and at the end, SUM over Account.
    I saw that there is a patch to fix an issue when different aggregation rules are implemented in a compressed cube and I asked the DBA folks to apply it. They told me that the patch cannot be applied because we have an advanced version already installed (Patch 11.2.0.1 ).
    These are the details of what we have installed:
          OLAP Analytic Workspace       11.2.0.3.0 VALID
          Oracle OLAP API 11.2.0.3.0 VALID
          OLAP Catalog 11.2.0.3.0 VALID
    Is there any other patch that needs to be applied to fix this issue? Or it's already included in the version we have installed (11.2.0.3.0)?
    Is there something wrong in the definition of my fact table and that's why I'm not getting the right results?
    Any help will be really appreciated!
    Thanks in advance,
    Martín

    Not sure I would have designed the dimensions /cubes as you,  but there is another method you can obtain distinct counts.
    Basically relies on using basic OLAP DML Expression language and can be put in a Calculated Measure, or can create two Calculated measures
    to contain each specific result.  I use this method to calculate distinct counts when I want to calculate averages, etc ...
    IF account_id ne -1 and (recency_date GT today-365) THEN -
    CONVERT(NUMLINES(UNIQUELINES(CHARLIST(Recency_date))) INTEGER)-
    ELSE IF account_id ne -1 and (recency_date GT today-730 and recency_date LE today-365) THEN -  
    CONVERT(NUMLINES(UNIQUELINES(CHARLIST(Recency_date))) INTEGER)-
    ELSE NA
    This exact code may not work in your case, but think you can get the gist of the process involved.
    This assumes the aggregation operators are set to the default (Sum), but may work with how you have them set.
    Regards,
    Michael Cooper

  • Distinct Count Function-how to use properly

    Hello,
    I am new to using forums & have only been using Crystal since May of 2009, so i hope i do this correctly & provide the appropriate information.  i've looked for this answer in what's been posted but cannot find it.  Some things i've read I don't really understand.  I only know how to use the functions that are in the software, i don't know how to write them myself (i think that's when people have referred to SQL code or basic syntax)
    I have CR Professional, version 11.0.0.1282 (Crystal Reports XI).
    I work at a county health dept and we have a annual medicaid cost report,  I am linking Crystal to our EMR billing module.  i have my report sorted by insurance, ie medicaid, bcbs, abw, hpm etc.  and within each ins group i have the clients ID, DOS (date of service), procedure code, charge amt, ins pmt & patient pmt.  i have totaled the charges & pmts for each group-works fine.  i even have been able to create the formula to adj out the duplicate entries in the billing module (a service was entered wrong then adjusted out then re-entered correctly-without my formula crystal was pulling both these records and adding them to total charges.)
    Where my problem lies and what my question is:  I need to count encounters, an encounter is the visit, but each visit could have 2 or more procedure codes.   So this results in multiple lines on my report for one visit, which i want for the charges to add correctly, but it makes my visit count to high. So I read about the distinct count function, of which there are three listed & i'm having a hard time understanding the differences.  What i tried is: a distinct count of the acct ID-so the same acct ID's are only counted the one time.  But some clients see us more than once per year, meaning the acct ID is the same but the DOS is different.  For this client that would be 2 visits.  But crystal is counting this as 1.
    Saying what i want to do is this:  Count as 1 when the acct ID and DOS are the same.  I've tried using the different distinct counts but when i check my formula it always has errors.  So I'm sure my lack of knowledge is what's holding me up-i fully believe crystal can do this.
    Any help would be greatly appreciated.

    I create a dummy table, set up acc_id and DOS and Charge.
    Created a running total
    Summarized acc_id
    Type of summary Count
    Evaluated using a formula
         <> previous ()
    and reset on ACC_ID
    My groups were sorted by acc_id and date
    where there were multiple visits on the same DOS my count was 0
    where the dos changed it would count accordingly.
    You may need to use two Running totals to get the complete picture.

  • Distinct Count SSAS

    Hi,
    I’m facing a little issue to calculate a distinct count of number of clients in SSAS OLAP Cube. The difficulty appears for the credited client’s accounts, in other words, for the clients how have credit (quantity = -1) or for the clients
    how have bought the product and they receive a credit after (quantity = 0). My actual distinct count in my cube considers these two cases as real buying transaction, but in fact they’re not.  I’ve checked in SSAS to make a distinct count with the expression
    (SUM Quantity > 1), but I didn’t find nothing. Now I’m thinking to model these cases directly in my Datawarehouse, but I don’t see how can’t do it.  Can anyone de give me a little help? Thanks.

    Hi Merouane,
    According to your description, you want to count the members with the condition quantity=-1, right? In this case, we can use Filter function inside the Count function. The query will looks like below.
    Count(Filter([Product].[Product].[Product], [Measures].[Internet Order Quantity] =-1))
    However, the Filter function might cause a performance issue, we can change the query to
    Sum(
       [Product].[Product].[Product],
       Iif([Measures].[Internet Order Quantity] =-1,1,0))
    For the detail information about it, please refer to the link below.
    http://sqlblog.com/blogs/mosha/archive/2007/11/22/optimizing-count-filter-expressions-in-mdx.aspx
    Regards,
    Charlie Liao
    TechNet Community Support

  • Distinct count mdx fails

    Hi,
    I have a question about performing a distinct count of number of clients in my cube OLAP. 
    My clients-dimension table is populated from 4 different databases, this means that I can find the same clients with different Clients_ID (Natural key), because each client has a different ID in every database.  
    I want to calculate a distinct count on client’s phone number because it’s the same record in all Databases, I always get a big number which is not the right result.  I checked deeply the issue and I found that the query I set seems
    to not perform the distinct count right on the phone number.
    The small test I did with only filters (see screenshot below) let me believe that my query is performing the distinct count on each client ID instead of the phone number.
    Here it is the query I used to perform my distinct count:
    WITH SET MySet AS
    Filter(
    {[Dim Date].[Year].&[2014]} *
    {[DIM FA Clients].[FaCuNumberX].[FaCuNumberX]},[Measures].[QQT - Fact Ventes]>1 or [Measures].[QQT - Fact Ventes]=1)
    MEMBER MEASURES.SETDISTINCTCOUNT AS
    DISTINCTCOUNT(MySet)
    SELECT {MEASURES.SETDISTINCTCOUNT} ON 0
    FROM [CubeAll]
    I don’t know why the filter on this mdx query doesn’t work properly like an SQL group by.
    Thanks for help! 

    Hi Merouane,
    According to your description, you want to calculated to the numbers of client by count distinct Phone Number, right?
    In your scenario, you can add a distinct count measure in your project. Distinctcounts are one of the most demanding requests that can be placed on a MOLAP database, caused by the large number of dimensional attributes that typically exist in a cube. Here
    is a blog which describe several solutions for distinctcount in a SSAS project, please refer to the link below to see the detais.
    http://www.mssqltips.com/sqlservertip/3043/different-options-for-creating-a-distinct-count-measure-in-ssas/
    Regards,
    Charlie Liao
    TechNet Community Support

  • Distinct Count in Explorer

    This is from BOB post, which was posted in 2008. Now it's 2013 and there is no solution by SAP? We are doing a POC on Explorer, this is probably time to scrap it. Very frustrating! Is there any
    Hi,
    We have 2 tables used in universe "orders" and
    "order_line_product_item" from where we are pulling data in explorer indexes.
    We have issues getting distinct count of
    customers in explorer when we bring data from order line product item level
    facets/dimension.
    Just wondering if anyone else had solution of how to
    handle this on explorer side?
    At universe level we using count (distinct cust key), which is working at
    webintelligence.
    Looks like BO XI R3 further enhanced on handling this kind
    of situation by implementing delegated measures, but don't find anything similar
    to it in BO explorer.
    Occurrences is always getting us count at the lowest grain level(basically row level
    counts, but we are looking for distinct counts though !) .
    Is getting
    distinct counts limitation in explorer?
    Any help will be greatly
    appreciated.
    Thanks,
    ~SK
    Courtesy of Sachin

    Hello,
    So if you have a calculation(Webi) function(Excel) built into the two tables you are using from the data source you might try 'configuring' the data as 'Occurance' from the workspace you created or after the file in index if you're using excel.  If you are using a universe as a data source for the exploration view set you can attempt to drag the 'measure' needed (count) into the workspace option "measure" when creating the workspace.
    I do hope this helps

  • MSSQL2005 Analysis Service Distinct Count

    hi,
    i am currently trying to build a distinct count on my cube (mssql2005 analysis services).
    But after i added the discount count on the field i want to and start the processing, the following errors appear.
    - Errors in the OLAP storage engine: The sort order specified for distinct count records is incorrect.
    - Errors in the OLAP storage engine: An error occurred while processing the 'FACT VIEW STATISTIC' partition of the 'FACT VIEW  STATISTIC 1' measure group for the 'Accident Statistic' cube from the OLAP_PROJECT database.
    the count measure works fine.
    will appreciate any help on this distinct count problem.
    thanks in advance.
    HY

    I also received this error:
    "Errors in the OLAP storage engine: The sort order specified for distinct count records is incorrect. "
    Running SQL Server 2005 SP2 Enterprise Edition
    The collation between SQL Server and Analysis Services was the same.
    The distinct count was on a character data type.
    There were no NULLs in the data.
    The cube was processing fine until new data was added.
    After some investigation into the data it seems that the culprit was one row that the data length was 13 characters on the column of the distinct count. Everything else was less than 13 characters. (See results below). Updating this one row solved the problem. The exact value of the data is: '1-4296-175-9'
    Here is a result set:
    select len(columnname) as data_length, count(*) as count
    from [tablename]
    group by len(columnname)
    order by data_length
    data_length   count
    2    3
    5    1
    6    3
    7    2
    9    1
    10    856
    13    1
    My question though is if SQL2005 can do distinct counts on strings then why choke on one row with an extra length?

  • Accumulative Distinct Counts

    I’ve been at this for two days now. Could someone lead me down the right path? Given the following data set:
    create table data_owner.test_data
    item_number varchar2(10 byte),
    store_number varchar2(10 byte),
    calendar_year varchar2(10 byte),
    calendar_week varchar2(10 byte),
    units_sold integer
    insert into test_data(item_number, store_number, calendar_year, calendar_week, units_sold)
    values ('1111', '31', '2010', '51', 4)
    insert into test_data(item_number, store_number, calendar_year, calendar_week, units_sold)
    values ('1111', '16', '2010', '51', 2)
    insert into test_data(item_number, store_number, calendar_year, calendar_week, units_sold)
    values ('1111', '31', '2010', '52', 3)
    insert into test_data(item_number, store_number, calendar_year, calendar_week, units_sold)
    values ('1111', '27', '2010', '52', 1)
    insert into test_data(item_number, store_number, calendar_year, calendar_week, units_sold)
    values ('1111', '16', '2011', '1', 3)
    insert into test_data(item_number, store_number, calendar_year, calendar_week, units_sold)
    values ('1111', '27', '2011', '2', 5)
    insert into test_data(item_number, store_number, calendar_year, calendar_week, units_sold)
    values ('1111', '20', '2011', '2', 4)
    insert into test_data(item_number, store_number, calendar_year, calendar_week, units_sold)
    values ('2222', '27', '2010', '51', 3)
    insert into test_data(item_number, store_number, calendar_year, calendar_week, units_sold)
    values ('2222', '16', '2010', '52', 2)
    insert into test_data(item_number, store_number, calendar_year, calendar_week, units_sold)
    values ('2222', '20', '2010', '52', 1)
    insert into test_data(item_number, store_number, calendar_year, calendar_week, units_sold)
    values ('2222', '16', '2011', '1', 3)
    insert into test_data(item_number, store_number, calendar_year, calendar_week, units_sold)
    values ('2222', '31', '2011', '2', 3)
    select * from test_data
    item_number     store_number     calendar_year     calendar_week     units_sold
    1111     31     2010     51     4
    1111     16     2010     51     2
    1111     31     2010     52     3
    1111     27     2010     52     1
    1111     16     2011     1     3
    1111     27     2011     2     5
    1111     20     2011     2     4
    2222     27     2010     51     3
    2222     16     2010     52     2
    2222     20     2010     52     1
    2222     16     2011     1     3
    2222     31     2011     2     3
    My desired result is a sum of units sold and an accumulative distinct count of store numbers grouped by item, year, and week. i.e.:
    item_number     calendar_year     calendar_week     store_count     sum(units_sold)
    1111     2010     51     2     6
    1111     2010     52     3     4
    1111     2011     1     3     3
    1111     2011     2     4     9
    2222     2010     51     1     3
    2222     2010     52     3     3
    2222     2011     1     3     3
    2222     2011     2     4     3
    I can’t seem to get the store count right. I’ve been trying various methods of the count(distinct store_number) over (…) analytic function, but nothing works. Thanks.

    Hi,
    Interesting problem!
    When using analytic functions, you can't use both DISTINCT and ORDER BY. Too bad; that sure would be convenient.
    The most general solution is to use aggregate functions instead of analytic functions, and do a self-join to pair every row ("table" l, for "later" in the query below) with every earleir row ("table" e below) for the same item:
    SELECT       l.item_number
    ,       l.calendar_year
    ,       l.calendar_week
    ,       COUNT (DISTINCT e.store_number)     AS store_count
    ,       SUM (l.units_sold)
         / COUNT (DISTINCT e.ROWID)          AS total_units_sold
    FROM       test_data   e
    JOIN       test_data   l      ON     e.item_number     = l.item_number
    AND                               e.calendar_year || LPAD (e.calendar_week, 2)
                                    <= l.calendar_year || LPAD (l.calendar_week, 2)
    GROUP BY  l.item_number
    ,       l.calendar_year
    ,       l.calendar_week
    ORDER BY  l.item_number
    ,       l.calendar_year
    ,       l.calendar_week
    ;You might think about storing a DATE (say, the date when the week begins) instead of year and week. It would simplify this query, and probably lots of other ones, too. I realize that might complicate some other queries, but I think you'll fiond a net gain.
    Thanks for posting the CREATE TABLE and INSERT statements; that helps a lot!
    Edited by: Frank Kulash on Nov 18, 2011 12:48 PM
    Here's an analytic solution. As you can see, it requires more code, and more complicated code, but it might perform better:
    WITH     got_r_num   AS
         SELECT     item_number
         ,     calendar_year
         ,     calendar_week
         ,     units_sold
         ,     ROW_NUMBER () OVER ( PARTITION BY  item_number
                                   ,                    store_number
                             ORDER BY        calendar_year
                             ,                calendar_week
                           )      AS r_num
         FROM    test_data
    SELECT DISTINCT
         item_number
    ,     calendar_year
    ,     calendar_week
    ,     COUNT ( CASE
                        WHEN  r_num = 1
                  THEN  1
                    END
               )             OVER ( PARTITION BY  item_number
                                      ORDER BY      calendar_year
                          ,          calendar_week
                                 )                    AS store_count
    ,       SUM (units_sold) OVER ( PARTITION BY  item_number
                                    ,             calendar_year
                          ,             calendar_week
                             )                         AS  total_units_sold
    FROM       got_r_num
    ORDER BY  item_number
    ,            calendar_year
    ,       calendar_week
    ;This approah will not work in all windowing situations. It's okay fo this job, but not if you wanted,for example, a count of distinct stores from the last 6 weeks, and the report covers more than 6 weeks.

  • Sum Distinct Count

    Is there a way to sum a distinct count?
    I have a distinct count placed on GF2 and need the Sum of the Distinct count of GF1.
    Is this possible?
    Thanks for any help and suggestions,
    Jen

    Hi Jen,
    Try this:
    1) Create a formula on the Group Footer 2:
    WhilePringtingRecords;
    Numbervar dc;
    dc := dc + distinctcount({database field}, {group});
    2) Create another formula to display the sum and place this on the GF1:
    WhilePringtingRecords;
    Numbervar dc;
    3) Create a reset formula and place it on the GH1:
    WhilePringtingRecords;
    Numbervar dc := 0;
    -Abhilash

  • Use Variance for Distinct Count of Group Results

    Post Author: Judith
    CA Forum: Crystal Reports
    Hi there,
    I am new to CR. I am using CR 2008. I am stuck (every two minutes) and it would be great, if you could help me with this one:
    I have a list of people who are talking to each other:A to B, B to A, C to D, D to A etc. Then I wanted to see, who has most friends and I have created Groups to have a Distinct Count on how many people are talking to A, and to B, and to C etc. that worked fine. What I would like to do is to find out is who of these has most people they are talking to. Or even better, what is the variance of the resulting subtotals. Simply using Variance or Maximum doesn't seem to work on the DistinctCount Summary.
    I would very much appreciate any help on this.
    Judith

    Post Author: Jagan
    CA Forum: Crystal Reports
    I understand the issue, I don't understand why you think DistinctCount at two different levels should total up. Consider this sample data:Facility, EmployeeA, 1A, 2B, 1B, 3
    Facility A's distinct count => 2Facility B's distinct count => 2Report's distinct count => 3
    Use DistinctCount() at the group level and create a formula to sum these counts yourself and print that in the report footer.

Maybe you are looking for

  • Distribution of sap systems

    hello, do anyone know the distribution of the sap systems to the different operating systems. is there a diagram, like a cake diagram, on the sap marketplace where you can see the distribution. thanks winfried geisselbrecht

  • Rt3290 linux

    Where i can download rt3290le/rt3290 driver for bluetooth ? I Have HP Pro Book G1 455.

  • Multiple Runs of Thread Problem

    hello friends , i have the following code where there are two threads and they will execute simultaneously but the error is <code> import java.util.*; import java.lang.*; class Demo1.java extends Thread public void run() for (int i=0;i<10li++) System

  • SAPLMEGUI number for ME22n differs

    Hi all, can you please advise with changing SAPLMEGUI number in vb scripts for ME22n. Sometimes, there is SAPLMEGUI:0010 and other times SAPLMEGUI:0015. Even when the users have the same screens in the beginning the SAPLMEGUI number differs. They als

  • HT1414 I can't restore my iPod after proper update!What should I do?

    I can't restore my iPod after proper update!It suddenly froze while updating. Now it is in restore mode and every time I try to restore it, it failes!Also bear in mind  that I have no backups of earlier versions of my iPod in my pc, since I formated