dbTalk Databases Forums  

How to get nth value of a sorted set

microsoft.public.sqlserver.olap microsoft.public.sqlserver.olap


Discuss How to get nth value of a sorted set in the microsoft.public.sqlserver.olap forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Dan
 
Posts: n/a

Default How to get nth value of a sorted set - 01-04-2006 , 03:46 PM






I have an Product Dimension as follows:
'toothbrush', 'paste', 'floss'

I have a Region Dimension as follows:
'Reg 1', 'Reg 2', 'Reg 3', ... , 'Reg N'

I have a measure called 'itemssold' that stores integer value of items sold.

I want to create a calculated measure that will return the nth value(NON
EMPTY AND > 0) of the set for a particular Product.

Example:
I want to create calculated member called "toothbrush_80th_percentile"
uing following data:
REG1 REG2 REG3
REG4 REG5
Dimension [Product].[toothbrush] 10 20 0 empty
18

I then need to filter/sort this as follows:
REG1 REG5 REG2
Dimension [Product].[toothbrush] 10 18 20

I would take the 80th percentile by using # of records in the set (3) * .8
= 2.4.
Truncate to 2.
Find position 2 in the filtered/sorted set and Return 18.

How can I accomplish this without calling external functions?

Thank You,

Daniel J. Zaccarine
Hanford Bay Associates, Ltd.



Reply With Quote
  #2  
Old   
Deepak Puri
 
Posts: n/a

Default Re: How to get nth value of a sorted set - 01-04-2006 , 09:34 PM






Hi Dan,

Assuming that you need a calculated member on the Region dimension,
which works with various measures:

Quote:
With Member [Region].[Reg 80Pctile] as
'Tail(BottomCount(Filter([Region].[Region].Members,
Not IsEmpty(Measures.CurrentMember)
And Measures.CurrentMember > 0) as FilteredRegions,
Int(0.8 * FilteredRegions.Count),
Measures.CurrentMember)).Item(0)'
Quote:

- Deepak

Deepak Puri
Microsoft MVP - SQL Server

*** Sent via Developersdex http://www.developersdex.com ***


Reply With Quote
  #3  
Old   
Dan
 
Posts: n/a

Default Re: How to get nth value of a sorted set - 01-09-2006 , 02:14 PM



Thanks. I was able to get this to work in an RS report, however it is too
slow. I calculate multiple percentiles per page.

Is it possible to store this as a measure directly in the cube so I can
speed up the query? I tried creating a calculated member but it did not
work. I tried modifying solve order so when the cube is processed it
created the averages I need before calculating the percentile, but I was
unable to get it to work.

Example:
Calculated member "Reg 80Pctile":
'Tail(BottomCount(Filter([Region].[Region].Members,
Not IsEmpty(Measures.CurrentMember)
And Measures.CurrentMember > 0) as FilteredRegions,
Int(0.8 * FilteredRegions.Count),
Measures.CurrentMember)).Item(0)'


Thank You,
___________________________

Daniel J. Zaccarine
Hanford Bay Associates, Ltd.

___________________________
"Deepak Puri" <deepak_puri (AT) progressive (DOT) com> wrote

Quote:
Hi Dan,

Assuming that you need a calculated member on the Region dimension,
which works with various measures:


With Member [Region].[Reg 80Pctile] as
'Tail(BottomCount(Filter([Region].[Region].Members,
Not IsEmpty(Measures.CurrentMember)
And Measures.CurrentMember > 0) as FilteredRegions,
Int(0.8 * FilteredRegions.Count),
Measures.CurrentMember)).Item(0)'



- Deepak

Deepak Puri
Microsoft MVP - SQL Server

*** Sent via Developersdex http://www.developersdex.com ***



Reply With Quote
  #4  
Old   
Deepak Puri
 
Posts: n/a

Default Re: How to get nth value of a sorted set - 01-09-2006 , 06:19 PM



TopCount() might be faster for 80 Percentile:

Quote:
With Member [Region].[Reg 80Pctile] as
'Tail(TopCount(Filter([Region].[Region].Members,
Not IsEmpty(Measures.CurrentMember)
And Measures.CurrentMember > 0) as FilteredRegions,
1 + FilteredRegions.Count
- Int(0.8 * FilteredRegions.Count),
Measures.CurrentMember)).Item(0)'
Quote:

- Deepak

Deepak Puri
Microsoft MVP - SQL Server

*** Sent via Developersdex http://www.developersdex.com ***


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.