Solved

Unique Count and Unique Count to Date (MDX)

Posted on 2004-04-23
6
608 Views
Last Modified: 2008-02-01
Hello, can anybody indicate the MDX to calculate Unique Count to date ?

Having two Periods

Period        Unique Count        Unique Count to Date
First            10                        10
Second        4                          Unique Count (First + Second)


So if 2 of the 4 items are contained in the first period, then the unique
count should be 10 + 2 = 12

Thanks in advance,
0
Comment
Question by:gflorez
  • 2
  • 2
6 Comments
 
LVL 4

Expert Comment

by:BulZeyE
Comment Utility
are the periods signified by integers?  I need much more information.  Table structures, PK and FK please..
       
0
 

Author Comment

by:gflorez
Comment Utility
This is just one large fact table and the date/period is defined as datetime type which is used to create a time dimension (year-week). Then I have an integer to find the unique occurences of an event within each week.


Date                            EventType
2/2/2003                       4
2/2/2003                       5
2/9/2003                       6                      
2/9/2003                       4
2/21/2003                     6                      


So going back to my question:

Date                     Count Unique for Period             Count Unique To Date
2/3/2003                    2                                                   2
2/9/2003                    2                                                   3
2/21/2003                  1                                                   3      

So for the week of 2/21/2003, the eventid # 6 was already counted for the week of 2/9/2003 so it should not be counted the next time it occurs.

Thanks


0
 

Author Comment

by:gflorez
Comment Utility
Now, if it helps ... I can recreate the fact table from the following tables structure:

EventDesc                    Events

EventID                        EventID
EventStarts                  EventDate
Description                   EventLocation
                           

The PK is EventID, right now, there are many eventdates and I need to count only the first occurence in my cube.
0
 
LVL 4

Accepted Solution

by:
BulZeyE earned 500 total points
Comment Utility
Try this:

create table table1 (datefield datetime, eventid int)

insert into table1
(datefield, eventid)
select
'2/2/2003',                      4
union all
select
'2/2/2003',                       5
union all
select
'2/9/2003',                       6                      
union all
select
'2/9/2003',                     4
union all
select
'2/21/2003',                     6    

select t2.datefield,
       t2.datecount,
       count(distinct t1.eventid)
  from table1 t1
 inner join (select datefield, count(distinct eventid) datecount
               from table1
              group by datefield) t2
  on t1.datefield <= t2.datefield
group by t2.datefield, t2.datecount
order by 1

0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

When you hear the word proxy, you may become apprehensive. This article will help you to understand Proxy and when it is useful. Let's talk Proxy for SQL Server. (Not in terms of Internet access.) Typically, you'll run into this type of problem w…
Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Viewers will learn how to use the INSERT statement to insert data into their tables. It will also introduce the NULL statement, to show them what happens when no value is giving for any given column.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now