Count distinct derived measure on SCD type 2 dimension

Hi,
I have 2 dimension tables with SCD type 2 and one fact table :
DIM1 :
DIM1_SURR_KEY
DIM1_NAT_KEY
DIM1_PROPERTY1
DIM1_PROPERTY2
EFFECTIVE_DATE
EXPIRATION_DATE
DIM2 :
DIM2_SURR_KEY
DIM2_NAT_KEY
DIM2_PROPERTY1
DIM2_PROPERTY2
EFFECTIVE_DATE
EXPIRATION_DATE
FACT :
DIM1_SURR_KEY
DIM2_SURR_KEY
MEA1
MEA2
Dimension and fact tables are joined with : DIM1_SURR_KEY and DIM2_SURR_KEY.
In my business layer fact table, I would like to define this derived measure : count distinct of DIM1_NAT_KEY.
I tried to add new source for the fact table. I also tried an alias of DIM1 in physical layer.
Nothing works as I want : In Answers, if I select the fact and the count distinct, it works. Even if I select property of DIM1. But if I select property of DIM2, my count distinct return 0 (in SQL sent to Oracle DB, the formula is replaced with NULL).
Is it possible (and how) to count the number of Nat_Key with a derived measure defined in business layer ?
If not, I’ll define materialized view on fact table with natural key and dimension ID.
My first goal is to avoid end user to redefine derived column in Answers for each reports.
Thanks for your help

Hi,
my advise is to map the DIM1_NAT_KEY iside the Fact Table of the Business Model, so you have a new Logical Table Source inside the Logical Fact Table that maps the DIM1_NAT_KEY as a measure. Define the Level for this Logical Table Source and set the COUNT DISTINC aggregation. In this way OBIEE knows that that measure is inside a fact an it treat like that.
I hope it helps.
Regards,
Gianluca

Similar Messages

  • SCD type 2 Dimension default expiration date

    I am using OWB 10.2.0.2.8 and exploring the SCD handling for dimensions.
    I have setup a simple dimension with a single level (no hierarchy) using the Wizard, set the SCD property to type 2 and chosen the Trigger History attributes.
    When I now use the dimension in a mapping (basic population from a base table), I want to set the effective date and expiration dates. I am calling a custom function to derive the effective date = current business date and want set the expiration date to a function based value (a system high date rather than NULL).
    The dimension properties in the mapping allow a value to be entered (e.g. TO_DATE('31-dec-9999','DD-MON-YYYY') but not a function call. I am getting the following validation error:
    "VLD-5011: Dimension RISK_CLASS_DIM: The Default Expiration Date of closed records for dimension RISK_CLASS_DIM should be an expression of type DATE.
    Value PKG_CONSTANTS.EFFECTIVE_HIGH_DATE is not a valid date: PLS-00201: identifier PKG_CONSTANTS.EFFECTIVE_HIGH_DATE must be declared"
    Any suggestions?

    the current flag could be set in a Derived Column with an expression like: RowEffectiveDt < GETDATE() && RowExpirationDt >= GETDATE() ? "Y" : "N"
    http://msdn.microsoft.com/en-us/library/ms141680.aspx ? : operator
    http://msdn.microsoft.com/en-us/library/ms139875.aspx
     GETDATE()
    Please mark the post as answered if it answers your question | My SSIS Blog:
    http://microsoft-ssis.blogspot.com |
    Twitter

  • Partitioning SCD Type 2 dimensions and possible update sto partition key

    Hi,
    We have a fact table which only gets inserts and are considering range partitioning this on sell_by_date (as can archive off products which long past sell by date) and hash sub-partition on product_id.
    Heard about partition wise joins and are considering partitioning the SCD Type 2 product dimension in similar way, range partition on product_sell_by_date and sub-partition by hash on product_id in oredr to gte benefiit of partition-wise joins.
    However, is possibility that product_sell_by_date could be updated via delta loads which maintian the SCD type 2 - in theory this attribute shouldn't be updated much.
    Any thoughts, generally on partitioning dimension tables and partition keys which can be updated.
    Many Thanks

    1. Create a function as mentioned by you "max value +1 on grouping of data "on target schema.
    2. Map to the target column
    3. select TARGET as exection area in interface ( don't select source or staging) for this column in interface mapping...
    4. select option only INSERT ( remove de-select UPDATE option) for this column in interface mapping.
    5. Execute the interface.
    Please let me know if this works
    Edited by: neeraj_singh on 6 Aug, 2012 10:38 PM
    Edited by: neeraj_singh on 7 Aug, 2012 1:55 AM

  • COUNT DISTINCT for measure

    Hello!
    I know that I am repeating this question, but I did not find any clear answer on metalink, newsletter or this forum.
    There is an article on Metalink: How To Determine The Number Of Members Per Hierarchy Level Of a Dimension: Note:429614.1. This is not exactly what I need.
    Also I found some replies from Keith to use SUM and MAX aggregations - this also does not help.
    I will give my example:
    Assume we have
    Two dimensions ITEMS and STORES each having two levels
    ITEMS: CATEGORY-PRODUCT
    STORES: REGION-STORE
    one measure REFERENCE
    Assume that we loaded REFERENCE with 1 on each ITEM/STORE where we had sales.
    Now if we aggregate ITEMS using SUM we receive unique references on level CATEGORY, but how could we receive unique references per REGION/CATEGORY?
    If we do MAX across STORES when we just receive the best store references for CATEGORY. That is not what I want.
    Are there any solution? I have seen that P_S asked Keith for magic file which propose 3 approaches. Could I pretend to one copy of this file?
    BIG THANKS in advance!
    Regards,
    Kirill Boyko ([email protected])

    Hi Kirill
    I will send you the file and hopefully it will help you create a solution. If not, email me directly and I will work with you to see if we can resolve this specific requirement.
    Keith
    Keith Laker
    Oracle EMEA Consulting
    OLAP Blog: http://oracleOLAP.blogspot.com/
    OLAP Wiki: http://wiki.oracle.com/page/Oracle+OLAP+Option
    DM Blog: http://oracledmt.blogspot.com/
    OWB Blog : http://blogs.oracle.com/warehousebuilder/
    OWB Wiki : http://wiki.oracle.com/page/Oracle+Warehouse+Builder
    DW on OTN : http://www.oracle.com/technology/products/bi/db/11g/index.html

  • VLD-0363 on SCD Type 2

    Hi all,
    I'm getting the following error while validating a scd type 2 dimension:
    "VLD-0363: For Slowly Changing Strategies Type-II Dimension DIM_A, if any of the trigger, effective date or expiration date is set for a level then all of them must be set"
    This is because I'm trying to create a dimension similar to this:
    DIM_A
    LEVEL_A
    DT_BEGIN --effective date
    DT_END --expiration date
    COD_A
    ID_A
    DESC_A
    LEVEL_B
    DT_BEGIN --effective date
    DT_END --expiration date
    COD_B
    ID_B
    DESC_B
    LEVEL_A_COD_A -- trigger history
    I don't want to keep history on the descriptions because I can assume that, if the description changes, then it must be a typo or some kind of correction. I just want to keep history of the changes in the hierarchy.
    OWB doesn't let me do this...
    Does this make any sense to you? What is your opinion? Have you ever try to do something like this? Are there any workarounds?
    Thank you for your comments.
    Best Regards.

    Hi,
    my advise is to map the DIM1_NAT_KEY iside the Fact Table of the Business Model, so you have a new Logical Table Source inside the Logical Fact Table that maps the DIM1_NAT_KEY as a measure. Define the Level for this Logical Table Source and set the COUNT DISTINC aggregation. In this way OBIEE knows that that measure is inside a fact an it treat like that.
    I hope it helps.
    Regards,
    Gianluca

  • OBIEE SCD type 2

    Hi
    There are three tables in the database.
    One is a dimension scd type 2 another a fact and another a calendar table
    If i have
    Name, age, Start Date, End Date, Current Flag
    mary Jones , 20, 01-JAN-2010 , 20-JAN-2010,0
    mary Roberts,20,21-JAN-2010,12-DEC-4712,1
    I will join my table to a fact which also has dates.. my problem is this
    If i create a daily report everything works fine. I can see 1 name from dimenstion and the relevent facts... which is good..
    But if i run by month i get both names returned which is right... but i only want the most current name in that month even though the facts are getting split right
    is there any way i can get the latest name from my dimension type 2 for the month selected and the relevent facts..

    does your current flag (i assume it as from SCD Type 2 dimension) establishes which record is current?
    If the above statement is false, let me know what is that which determines the most recent update?
    -bifacts
    http://www.obinotes.com
    Edited by: bifacts on Oct 21, 2010 10:05 AM

  • Set Aggregation type of Count Distinct to use correct table aggregation in

    Hi there,
    Currently I use OBIEE 10.1.3.4.1 , and there is a case where a fact table consist of 2 logical table source: detail and aggregate table, which has some measure using count distinct as aggregation type. The problem is everytime I browse the measure with no dimension at all , it always use detail table not aggegation one..
    Really appreciate for any suggestion ..
    thanks a lot

    Hi,
    I don't think it's the same case as mine. Let say I have 2 table : detail and aggegate
    Detail Table consists 4 fields:
    *) Period
    *) Market
    *) Region
    *) Measure : Customer ID, Sales
    Aggregate Table consists 3 fields :
    *) Period
    *) Region
    *) Measure : Customer ID, Sales
    in the measure I set aggregation type for each field:
    *) Sales >> set as Sum
    *) Customer ID >> copy as "Number of Customer" and set as Count Distinct
    In each LTS' contents I set the level of aggregation using "Get Levels" feature..
    Then I try to browse via Presentation and do some querys belows:
    a) only choose single field of measure : Sales, the session shows that the value is taken from aggregation table and just as I expected.
    b) choose period and sales, the session shows that the values are taken from aggregation table, and still just as I expected.
    c) choose period, sales , and market, the session shows that the values are taken from detail table, just as I expected.
    d) only choose single field of measure : "Number of Customer", the session shows that the value is taken from detail table , this is NOT as I expected. It suppose to take the value from aggregation table..
    e) choose period and "Number of Customer", the session shows that the value is taken from detail table , this is also NOT as I expected. It suppose to take the value from aggregation table..
    I've tried to override the aggregation , but still confuse how to apply in measure "Number of Customer" and did not work at all..
    any idea ?
    thanks a lot

  • Distinct count inside a measure group with other measures

    Hello,
    I have 1 distinct count inside a measure group with other measures, sum, count etc. I know this is not recommended due to poor processing performance and query response time.
    Processing performance I can live with if it means not having another measure group, which increases processing time anyway.
    I have used the recommended approach before and it generated many questions about what this second measure group is for (visible via excel), even though I made the distinct count appear in the main measure group via a calculated measure.
    (it would be nice if you could hide measure groups)
    However my question is: is query response time only effected when the distinct count is used in the query? Or is query response time effected regardless if the distinct count is used or not??
    Below is an extract from the 2005 distinct count optimizer white paper. It’s not completely clear but I assume if effects queries regardless if distinct count is used or not?
    "By adding other measures to the measure group holding a distinct count measure, all of the other measures will be at the same granularity as the distinct count measure, resulting in inefficient data structures and suboptimal
    queries."

    You might also be interested in reading this blog post, which deals with a similar scenario, to get a feeling for some of the things that might be going on behind the scenes:
    http://cwebbbi.wordpress.com/2012/11/27/storage-engine-caching-measures-and-measure-groups/
    Chris
    Check out my MS BI blog I also do
    SSAS, PowerPivot, MDX and DAX consultancy
    and run public SQL Server and BI training courses in the UK

  • 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

  • Grand Total with Count Distinct

    Hi,
    I want to use grand total to count distinct my data,
    I had physical map ActivityId into my fact and set count distinct to its aggregation rules.
    then when i create my report the anwser is OK.(count distinct ActivityID). But in grandtotal is sum.
    The aggregation Rules in BI Awnser is set it Default.
    [Pic >> http://image.ohozaa.com/i/866/tablecountdisctinct.jpg ]
    i don't know why , i try to set many thing but it isn't work
    Thank ,Regard.
    And sorry about my English Language.

    couple of things required here..
    how did you build this measure in rpd?
    Is that physical mapped or logical mapped column(derived column)?
    Map it as physically and apply aggregation rule on top of it to: CountDistinct
    Now, pull the column in front-end it has to give you proper sub-total/total..
    Or, Try putting the formula in front-end in fx of the column and try..

  • Count&Count Distinct

    Hi Gurus,
    In one of OBIEE blogs I studied "Aggregation should only be performed on measure columns, with the possible exception of the aggregation COUNT and Count Distinct"....my Question is what happens if we apply count&count distinct aggregation rules to measures because we are using that in our project,what are problems we will face?

    User wrote:
    you mean it executes a sub query internally to count and later it sum the result..correct.- You can ship the total calculations to the underlying RDBMS if 'Report Based Total' is not ticked, otherwise if it is, the BI Server computes the subtotal.
    and in your answers "No" mean results coming by putting sum in criteria are different ..right- Yes thats what I mean, sorry if unclear - Are your totals correct now? Failing that try 'server complex aggregate' but this is usually only requried if your deriving calculations in Answers (ie % of total etc).

  • How to count distinct excluding a value in business layer?

    Hi all,
    I'm having a column which has many values. I need to make this is as a measure with count distinct aggregator. But i should not count 0 in the column. How can i do this. If i try to use any condition means the aggregator option is disables. Please help
    Thanks

    Look this example:
    I made in BMM in the SALES fact table measure:
    Count_Distinct_Prod_Id_Exclude_Prod_Id_144
    I'll count distinct PRODUCTS.PROD_ID, but exclude PROD_ID=144 in counting.
    Make this measure like this:
    1. New object/Logical column
    2. Go to data type tab and click EDIT on the logical table table source
    3. Now, in the general tab add join to a table (in my case PRODUCTS)
    4. Go to the column mapping tab -> show unmapped columns
    5. In the new column (in my case Count_Distinct_Prod_Id_Exclude_Prod_Id_144) write code like similar:
    CASE WHEN "orcl".""."SH"."PRODUCTS"."PROD_ID" = 144 THEN NULL ELSE "orcl".""."SH"."PRODUCTS"."PROD_ID" END
    6. Click OK and close the logical table source window
    7. Now, in the logical column window go to aggregation tab and choose COUNT DISTINCT.
    8. Move the measure Count_Distinct_Prod_Id_Exclude_Prod_Id_144 in the presentation area
    9. Test in Answers (report cointains columns as follow)
    PROD_CATEGORY_ID
    Count_Distinct_Prod_Id_Exclude_Prod_Id_144
    And the result in the NQQuery.log is:
    select T21473.PROD_CATEGORY_ID as c1,
    count(distinct case when T21473.PROD_ID = 144 then NULL else T21473.PROD_ID end ) as c2
    from
    PRODUCTS T21473
    group by T21473.PROD_CATEGORY_ID
    order by c1
    Regards
    Goran
    http://108obiee.blogspot.com

  • Performance problem with more than one COUNT(DISTINCT ...) in a query

    Hi,
    (I hope this is the good forum).
    In the following query, I have 2 Count Distinct on 2 different fields of the same table.  Execution time is okay (2 s) with one or the other COUNT(DISCTINCT ...) in the SELECT clause, but is not tolerable (12 s) with both together in the query! I have
    a similar case with 3 counts: 4 s each, 36 s when together!
    I've looked at the execution plan, and it seems that with two count distinct, SQL server sorts the table twice before joining the results.
    I do not have much experience with SQL server optimization, and I don't know what to improve and how. The SQL is generated by Business Objects, I have few possibilities to tune it. The most direct way would be to execute 2 different queries, but I'd like
    to avoid it.
    Any advice?
    SELECT
      DIM_MOIS.DATE_DEBUT_MOIS,
      DIM_MOIS.NUM_ANNEE_MOIS,
      DIM_DEMANDE_SCD.CAT_DEMANDE,
      DIM_APPLICATION.LIB_APPLICATION,
      DIM_DEMANDE_SCD.CAT_DEMANDE ,
      count(distinct FAITS_DEMANDE.NB_DEMANDE_FLUX),
      count(distinct FAITS_DEMANDE.NB_DEMANDE_RESOL_NIV1)
    FROM
      ALIM_SID.DIM_MOIS INNER JOIN ALIM_SID.DIM_JOUR ON (DIM_JOUR.SEQ_MOIS=DIM_MOIS.SEQ_MOIS)
       INNER JOIN ALIM_SID.FAITS_DEMANDE ON (FAITS_DEMANDE.SEQ_JOUR=DIM_JOUR.SEQ_JOUR)
       INNER JOIN ALIM_SID.DIM_APPLICATION ON (FAITS_DEMANDE.SEQ_APPLICATION=DIM_APPLICATION.SEQ_APPLICATION)
       INNER JOIN ALIM_SID.DIM_DEMANDE_SCD ON (FAITS_DEMANDE.SEQ_DEMANDE_SCD=DIM_DEMANDE_SCD.SEQ_DEMANDE_SCD)
    WHERE
      ( ( DIM_MOIS.NUM_ANNEE_MOIS ) >201301
    GROUP BY
      DIM_MOIS.DATE_DEBUT_MOIS,
      DIM_MOIS.NUM_ANNEE_MOIS,
      DIM_DEMANDE_SCD.CAT_DEMANDE,
      DIM_APPLICATION.LIB_APPLICATION

    Here is the script, nothing original. Hope this helps.
    -- Fact table :
    -- foreign keys begin by FK_,
    -- measures to counted (COUNT DISTINCT) begin with NB_
    CREATE TABLE [ALIM_SID].[FAITS_DEMANDE](
        [SEQ_JOUR] [int] NOT NULL,
        [SEQ_DEMANDE] [int] NOT NULL,
        [SEQ_DEMANDE_SCD] [int] NOT NULL,
        [SEQ_APPLICATION] [int] NOT NULL,
        [SEQ_INTERVENANT] [int] NOT NULL,
        [SEQ_SERVICE_RESPONSABLE] [int] NOT NULL,
        [NB_DEMANDE_FLUX] [int] NULL,
        [NB_DEMANDE_STOCK] [int] NULL,
        [NB_DEMANDE_RESOLUE] [int] NULL,
        [NB_DEMANDE_LIVREE] [int] NULL,
        [NB_DEMANDE_MEP] [int] NULL,
        [NB_DEMANDE_RESOL_NIV1] [int] NULL,
     CONSTRAINT [PK_FAITS_DEMANDE] PRIMARY KEY CLUSTERED
        [SEQ_JOUR] ASC,
        [SEQ_DEMANDE] ASC,
        [SEQ_DEMANDE_SCD] ASC,
        [SEQ_APPLICATION] ASC,
        [SEQ_INTERVENANT] ASC,
        [SEQ_SERVICE_RESPONSABLE] ASC
    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY],
     CONSTRAINT [AK_AK_FAITS_DEMANDE_FAITS_DE] UNIQUE NONCLUSTERED
        [SEQ_JOUR] ASC,
        [SEQ_DEMANDE] ASC,
        [SEQ_DEMANDE_SCD] ASC,
        [SEQ_APPLICATION] ASC,
        [SEQ_INTERVENANT] ASC
    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
    ) ON [PRIMARY]
    GO
    ALTER TABLE [ALIM_SID].[FAITS_DEMANDE]  WITH CHECK ADD  CONSTRAINT [FK_FAITS_DEMANDE_DIM_APPLICATION] FOREIGN KEY([SEQ_APPLICATION])
    REFERENCES [ALIM_SID].[DIM_APPLICATION] ([SEQ_APPLICATION])
    GO
    ALTER TABLE [ALIM_SID].[FAITS_DEMANDE] CHECK CONSTRAINT [FK_FAITS_DEMANDE_DIM_APPLICATION]
    GO
    ALTER TABLE [ALIM_SID].[FAITS_DEMANDE]  WITH CHECK ADD  CONSTRAINT [FK_FAITS_DEMANDE_DIM_DEMANDE] FOREIGN KEY([SEQ_DEMANDE])
    REFERENCES [ALIM_SID].[DIM_DEMANDE] ([SEQ_DEMANDE])
    GO
    ALTER TABLE [ALIM_SID].[FAITS_DEMANDE] CHECK CONSTRAINT [FK_FAITS_DEMANDE_DIM_DEMANDE]
    GO
    ALTER TABLE [ALIM_SID].[FAITS_DEMANDE]  WITH CHECK ADD  CONSTRAINT [FK_FAITS_DEMANDE_DIM_DEMANDE_SCD] FOREIGN KEY([SEQ_DEMANDE_SCD])
    REFERENCES [ALIM_SID].[DIM_DEMANDE_SCD] ([SEQ_DEMANDE_SCD])
    GO
    ALTER TABLE [ALIM_SID].[FAITS_DEMANDE] CHECK CONSTRAINT [FK_FAITS_DEMANDE_DIM_DEMANDE_SCD]
    GO
    ALTER TABLE [ALIM_SID].[FAITS_DEMANDE]  WITH CHECK ADD  CONSTRAINT [FK_FAITS_DEMANDE_DIM_INTERVENANT] FOREIGN KEY([SEQ_INTERVENANT])
    REFERENCES [ALIM_SID].[DIM_INTERVENANT] ([SEQ_INTERVENANT])
    GO
    ALTER TABLE [ALIM_SID].[FAITS_DEMANDE] CHECK CONSTRAINT [FK_FAITS_DEMANDE_DIM_INTERVENANT]
    GO
    ALTER TABLE [ALIM_SID].[FAITS_DEMANDE]  WITH CHECK ADD  CONSTRAINT [FK_FAITS_DEMANDE_DIM_JOUR] FOREIGN KEY([SEQ_JOUR])
    REFERENCES [ALIM_SID].[DIM_JOUR] ([SEQ_JOUR])
    GO
    ALTER TABLE [ALIM_SID].[FAITS_DEMANDE] CHECK CONSTRAINT [FK_FAITS_DEMANDE_DIM_JOUR]
    GO
    ALTER TABLE [ALIM_SID].[FAITS_DEMANDE]  WITH CHECK ADD  CONSTRAINT [FK_FAITS_DEMANDE_DIM_SERVICE_RESPONSABLE] FOREIGN KEY([SEQ_SERVICE_RESPONSABLE])
    REFERENCES [ALIM_SID].[DIM_SERVICE] ([SEQ_SERVICE])
    GO
    ALTER TABLE [ALIM_SID].[FAITS_DEMANDE] CHECK CONSTRAINT [FK_FAITS_DEMANDE_DIM_SERVICE_RESPONSABLE]
    GO
    -- not shown : extended properties
    -- One of the dimension  tables (they all have a primary key named SEQ_)
    CREATE TABLE [ALIM_SID].[DIM_JOUR](
        [SEQ_JOUR] [int] IDENTITY(1,1) NOT NULL,
        [SEQ_ANNEE] [int] NOT NULL,
        [SEQ_MOIS] [int] NOT NULL,
        [DATE_JOUR] [date] NULL,
        [CODE_ANNEE] [varchar](25) NULL,
        [CODE_MOIS] [varchar](25) NULL,
        [CODE_SEMAINE_ISO] [varchar](25) NULL,
        [CODE_JOUR_ANNEE] [varchar](25) NULL,
        [CODE_ANNEE_JOUR] [varchar](25) NULL,
        [LIB_JOUR] [varchar](25) NULL,
        [LIB_JOUR_COURT] [varchar](25) NULL,
        [JOUR_OUVRE] [tinyint] NULL,
        [JOUR_CHOME] [tinyint] NULL,
     CONSTRAINT [PK_DIM_JOUR] PRIMARY KEY CLUSTERED
        [SEQ_JOUR] ASC
    )WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
    ) ON [PRIMARY]
    GO
    ALTER TABLE [ALIM_SID].[DIM_JOUR]  WITH CHECK ADD  CONSTRAINT [FK_DIM_JOUR_DIM_ANNEE] FOREIGN KEY([SEQ_ANNEE])
    REFERENCES [ALIM_SID].[DIM_ANNEE] ([SEQ_ANNEE])
    GO
    ALTER TABLE [ALIM_SID].[DIM_JOUR] CHECK CONSTRAINT [FK_DIM_JOUR_DIM_ANNEE]
    GO
    ALTER TABLE [ALIM_SID].[DIM_JOUR]  WITH CHECK ADD  CONSTRAINT [FK_DIM_JOUR_DIM_MOIS] FOREIGN KEY([SEQ_MOIS])
    REFERENCES [ALIM_SID].[DIM_MOIS] ([SEQ_MOIS])
    GO
    ALTER TABLE [ALIM_SID].[DIM_JOUR] CHECK CONSTRAINT [FK_DIM_JOUR_DIM_MOIS]
    GO

  • SCD type 2 in OBIEE

    Hi,
    I'm relatively new to OBIEE and trying to implement slowly changing dimension type 2.-- i.e. to look up the correct record in the customer dimension (A_FICC_ACCOUNT) based on the transaction date in the fact table (A_FICC_PROFITABILITY). The customer dimension has two time stamps (start_effective_date, end_effective_date), where end_effective_date will be set to NULL for the most recent record.
    So far I've set this up as a complex join in the physical layer, as follows:
    A_FICC_ACCOUNT.ACCOUNT_ID = A_FICC_PROFITABILITY.ACCOUNT_ID
    AND
    A_FICC_PROFITABILITY.DAYID >= A_FICC_ACCOUNT.START_EFFECTIVE_DATE AND A_FICC_PROFITABILITY.DAYID < A_FICC_ACCOUNT.END_EFFECTIVE_DATE
    OR
    A_FICC_PROFITABILITY.DAYID >= A_FICC_ACCOUNT.START_EFFECTIVE_DATE AND A_FICC_ACCOUNT.END_EFFECTIVE_DATE IS NULL
    When i run a report in Answers, the generated SQL is as follows:
    select distinct T2327.YEARCAPTION as c1,
    T13994.SHORT_NAME as c2,
    T13994.RANK_W12 as c3,
    T13994.RANK_W52 as c4,
    T2327.YEARID as c5
    from
    DIM_FICC_ACCOUNT T13994 /* A_FICC_ACCOUNT */ ,
    DIM_TIME T2327 /* A_FICC_TIME */ ,
    FACT_FICC_PROFITABILITY T13406 /* A_FICC_PROFITABILITY */
    where ( T2327.SKEY = T13406.TIME_ID and T13406.ACCOUNT_ID = T13994.ACCOUNT_ID and T13994.SHORT_NAME = 'PETEROLA' and (T13406.DAYID < T13994.END_EFFECTIVE_DATE or T13994.END_EFFECTIVE_DATE is null) and T13406.DAYID >= T13994.START_EFFECTIVE_DATE )
    order by c5, c2, c3, c4
    Ran directly against the (Oracle) database using an SQL client, it gives meaningful results according to the recorded historical changes in the dimension. (see attached screenshot). In Answers, however, the results are not correct (see attached screenshot).
    http://dl.dropbox.com/u/3345113/output.jpg
    Any tips as to what might be wrong would be greatly appreciated.
    best regards
    Magnus

    Magnus,
    As mentioned customer dimension (A_FICC_ACCOUNT) is a SCD type 2, what is the primary key on this table? I don't think it is ACCOUNT_ID alone.
    Usually there exists a surrogate key to keep track of any changes, thus it is on this surrogate key a join should exist with a fact table and applying a filter end_effective date is null should produce the correct result.
    If the above scenario is not true in your case, do let me know the structure of the customer dimension and fact table (only columns associated with customer dimension), with relation ship information please.
    J
    -bifacts
    http://www.obinotes.com

  • COUNT(DISTINCT) WITH ORDER BY in an analytic function

    -- I create a table with three fields: Name, Amount, and a Trans_Date.
    CREATE TABLE TEST
    NAME VARCHAR2(19) NULL,
    AMOUNT VARCHAR2(8) NULL,
    TRANS_DATE DATE NULL
    -- I insert a few rows into my table:
    INSERT INTO TEST ( TEST.NAME, TEST.AMOUNT, TEST.TRANS_DATE ) VALUES ( 'Anna', '110', TO_DATE('06/01/2005 08:00:00 PM', 'MM/DD/YYYY HH12:MI:SS PM') );
    INSERT INTO TEST ( TEST.NAME, TEST.AMOUNT, TEST.TRANS_DATE ) VALUES ( 'Anna', '20', TO_DATE('06/01/2005 08:00:00 PM', 'MM/DD/YYYY HH12:MI:SS PM') );
    INSERT INTO TEST ( TEST.NAME, TEST.AMOUNT, TEST.TRANS_DATE ) VALUES ( 'Anna', '110', TO_DATE('06/02/2005 08:00:00 PM', 'MM/DD/YYYY HH12:MI:SS PM') );
    INSERT INTO TEST ( TEST.NAME, TEST.AMOUNT, TEST.TRANS_DATE ) VALUES ( 'Anna', '21', TO_DATE('06/03/2005 08:00:00 PM', 'MM/DD/YYYY HH12:MI:SS PM') );
    INSERT INTO TEST ( TEST.NAME, TEST.AMOUNT, TEST.TRANS_DATE ) VALUES ( 'Anna', '68', TO_DATE('06/04/2005 08:00:00 PM', 'MM/DD/YYYY HH12:MI:SS PM') );
    INSERT INTO TEST ( TEST.NAME, TEST.AMOUNT, TEST.TRANS_DATE ) VALUES ( 'Anna', '110', TO_DATE('06/05/2005 08:00:00 PM', 'MM/DD/YYYY HH12:MI:SS PM') );
    INSERT INTO TEST ( TEST.NAME, TEST.AMOUNT, TEST.TRANS_DATE ) VALUES ( 'Anna', '20', TO_DATE('06/06/2005 08:00:00 PM', 'MM/DD/YYYY HH12:MI:SS PM') );
    INSERT INTO TEST ( TEST.NAME, TEST.AMOUNT, TEST.TRANS_DATE ) VALUES ( 'Bill', '43', TO_DATE('06/01/2005 08:00:00 PM', 'MM/DD/YYYY HH12:MI:SS PM') );
    INSERT INTO TEST ( TEST.NAME, TEST.AMOUNT, TEST.TRANS_DATE ) VALUES ( 'Bill', '77', TO_DATE('06/02/2005 08:00:00 PM', 'MM/DD/YYYY HH12:MI:SS PM') );
    INSERT INTO TEST ( TEST.NAME, TEST.AMOUNT, TEST.TRANS_DATE ) VALUES ( 'Bill', '221', TO_DATE('06/03/2005 08:00:00 PM', 'MM/DD/YYYY HH12:MI:SS PM') );
    INSERT INTO TEST ( TEST.NAME, TEST.AMOUNT, TEST.TRANS_DATE ) VALUES ( 'Bill', '43', TO_DATE('06/04/2005 08:00:00 PM', 'MM/DD/YYYY HH12:MI:SS PM') );
    INSERT INTO TEST ( TEST.NAME, TEST.AMOUNT, TEST.TRANS_DATE ) VALUES ( 'Bill', '73', TO_DATE('06/05/2005 08:00:00 PM', 'MM/DD/YYYY HH12:MI:SS PM') );
    commit;
    /* I want to retrieve all the distinct count of amount for every row in an analytic function with COUNT(DISTINCT AMOUNT) sorted by name and ordered by trans_date where I get only calculate for the last four trans_date for each row (i.e., for the row "Anna 110 6/5/2005 8:00:00.000 PM," I only want to look at the previous dates from 6/2/2005 to 6/5/2005 and get the distinct count of how many amounts there are different for Anna). Note, I cannot use the DISTINCT keyword in this query because it doesn't work with the ORDER BY */
    select NAME, AMOUNT, TRANS_DATE, COUNT(/*DISTINCT*/ AMOUNT) over ( partition by NAME
    order by TRANS_DATE range between numtodsinterval(3,'day') preceding and current row ) as COUNT_AMOUNT
    from TEST t;
    This is the results I get if I just count all the AMOUNT without using distinct:
    NAME     AMOUNT     TRANS_DATE     COUNT_AMOUNT
    Anna 110 6/1/2005 8:00:00.000 PM     2
    Anna 20 6/1/2005 8:00:00.000 PM     2
    Anna 110     6/2/2005 8:00:00.000 PM     3
    Anna 21     6/3/2005 8:00:00.000 PM     4
    Anna 68     6/4/2005 8:00:00.000 PM     5
    Anna 110     6/5/2005 8:00:00.000 PM     4
    Anna 20     6/6/2005 8:00:00.000 PM     4
    Bill 43     6/1/2005 8:00:00.000 PM     1
    Bill 77     6/2/2005 8:00:00.000 PM     2
    Bill 221     6/3/2005 8:00:00.000 PM     3
    Bill 43     6/4/2005 8:00:00.000 PM     4
    Bill 73     6/5/2005 8:00:00.000 PM     4
    The COUNT_DISTINCT_AMOUNT is the desired output:
    NAME     AMOUNT     TRANS_DATE     COUNT_DISTINCT_AMOUNT
    Anna     110     6/1/2005 8:00:00.000 PM     1
    Anna     20     6/1/2005 8:00:00.000 PM     2
    Anna     110     6/2/2005 8:00:00.000 PM     2
    Anna     21     6/3/2005 8:00:00.000 PM     3
    Anna     68     6/4/2005 8:00:00.000 PM     4
    Anna     110     6/5/2005 8:00:00.000 PM     3
    Anna     20     6/6/2005 8:00:00.000 PM     4
    Bill     43     6/1/2005 8:00:00.000 PM     1
    Bill     77     6/2/2005 8:00:00.000 PM     2
    Bill     221     6/3/2005 8:00:00.000 PM     3
    Bill     43     6/4/2005 8:00:00.000 PM     3
    Bill     73     6/5/2005 8:00:00.000 PM     4
    Thanks in advance.

    you can try to write your own udag.
    here is a fake example, just to show how it "could" work. I am here using only 1,2,4,8,16,32 as potential values.
    create or replace type CountDistinctType as object
       bitor_number number,
       static function ODCIAggregateInitialize(sctx IN OUT CountDistinctType) 
         return number,
       member function ODCIAggregateIterate(self IN OUT CountDistinctType, 
         value IN number) return number,
       member function ODCIAggregateTerminate(self IN CountDistinctType, 
         returnValue OUT number, flags IN number) return number,
        member function ODCIAggregateMerge(self IN OUT CountDistinctType,
          ctx2 IN CountDistinctType) return number
    create or replace type body CountDistinctType is 
    static function ODCIAggregateInitialize(sctx IN OUT CountDistinctType) 
    return number is 
    begin
       sctx := CountDistinctType('');
       return ODCIConst.Success;
    end;
    member function ODCIAggregateIterate(self IN OUT CountDistinctType, value IN number)
      return number is
      begin
        if (self.bitor_number is null) then
          self.bitor_number := value;
        else
          self.bitor_number := self.bitor_number+value-bitand(self.bitor_number,value);
        end if;
        return ODCIConst.Success;
      end;
      member function ODCIAggregateTerminate(self IN CountDistinctType, returnValue OUT
      number, flags IN number) return number is
      begin
        returnValue := 0;
        for i in 0..log(2,self.bitor_number) loop
          if (bitand(power(2,i),self.bitor_number)!=0) then
            returnValue := returnValue+1;
          end if;
        end loop;
        return ODCIConst.Success;
      end;
      member function ODCIAggregateMerge(self IN OUT CountDistinctType, ctx2 IN
      CountDistinctType) return number is
      begin
        return ODCIConst.Success;
      end;
      end;
    CREATE or REPLACE FUNCTION CountDistinct (n number) RETURN number 
    PARALLEL_ENABLE AGGREGATE USING CountDistinctType;
    drop table t;
    create table t as select rownum r, power(2,trunc(dbms_random.value(0,6))) p from all_objects;
    SQL> select r,p,countdistinct(p) over (order by r) d from t where rownum<10 order by r;
             R          P          D
             1          4          1
             2          1          2
             3          8          3
             4         32          4
             5          1          4
             6         16          5
             7         16          5
             8          4          5
             9          4          5buy some good book if you want to start at writting your own "distinct" algorythm.
    Message was edited by:
    Laurent Schneider
    a simpler but memory killer algorithm would use a plsql table in an udag and do the count(distinct) over that table to return the value

Maybe you are looking for

  • Mass Upload of BP Data

    Hi Experts, I have been tasked with looking at options to Upload 1,6 Million BP records into a Standalone SAP CRM Box. Business has decided that only BP Address data needs to be bought across from our ISU box. As I am not a Migration consultant, I am

  • Itunes wont recognize my ipod touch 5th generation and i tried updating itunes to 11.0.1 but i cant

    itunes wont recognize my ipod touch 5th generation and i tried updating itunes to 11.0.1 but i cant what should i do?

  • Read sensor and move servo

    Hi!, I have a proble. I don´t know how i must do to read sensors and at same time run the servos. I upload the program .VI http://www.gigasize.com/get.php?d=tg1jvvdzssc Thanks Attachments: servoaungulo6.vi ‏28 KB

  • Error -208 : There was an error in the music store

    This is truly getting old. I made the jump from 5.0.1 (which had sound problems) to 6 last night. I can play my music I imported from CD just fine (skips every now and then). But, when I try to play any of the music I paid handsomely for through iTun

  • Hex input using user dialog box.

    Hello I am trying to use the user dialog box to input data. I want to input the data as Hex. format. however as I select the input to be a number, it takes as a decimal number and there seems to be no option where I can change it to a hex format. Any