dbTalk Databases Forums  

Re: Topcount within second level

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


Discuss Re: Topcount within second level in the microsoft.public.sqlserver.olap forum.



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

Default Re: Topcount within second level - 06-14-2005 , 03:43 PM






Try using Generate() to iterate through the states:

Quote:
SELECT [TimePeriod].[Year].Members ON COLUMNS,
Generate([State].[State Code].Members,
TOPCOUNT([Vendor].[Vendor Name].Members,10,
[Measures].[Amount])) ON ROWS
FROM APData
Quote:

- Deepak

Deepak Puri
Microsoft MVP - SQL Server

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


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

Default Re: Topcount within second level - 06-14-2005 , 03:59 PM






Oops - need to include the current state, via CrossJoin:

Quote:
SELECT [TimePeriod].[Year].Members ON COLUMNS,
Generate([State].[State Code].Members,
CrossJoin({[State].CurrentMember},
TOPCOUNT([Vendor].[Vendor Name].Members,10,
[Measures].[Amount]))) ON ROWS
FROM APData
Quote:

- Deepak

Deepak Puri
Microsoft MVP - SQL Server

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


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

Default Re: Topcount within second level - 06-14-2005 , 06:30 PM



Thanks Deepak. That worked pretty well.

How do I eliminate rows with blank cells? I do not want to return anything
for states with no Amount. I want to return only 3 Vendors, if that's all a
state has with Amounts > 0.

Also would like to know if there is a way to submit this query through Excel.



"Deepak Puri" wrote:

Quote:
Oops - need to include the current state, via CrossJoin:


SELECT [TimePeriod].[Year].Members ON COLUMNS,
Generate([State].[State Code].Members,
CrossJoin({[State].CurrentMember},
TOPCOUNT([Vendor].[Vendor Name].Members,10,
[Measures].[Amount]))) ON ROWS
FROM APData



- 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: Topcount within second level - 06-14-2005 , 07:52 PM



Hi Chris,

Using the Non Empty option on rows in the MDX query should suppress
blank rows:

Quote:
SELECT [TimePeriod].[Year].Members ON COLUMNS,
Non Empty Generate([State].[State Code].Members,
TOPCOUNT([Vendor].[Vendor Name].Members,10,
[Measures].[Amount])) ON ROWS
FROM APData
Quote:
Don't know any way to directly submit an MDX query in Excel; but if you
select Field Settings/Advanced Options for the [Vendor Name] field, the
Show Top .. feature can be enabled. This might give you similar results
if [State Code] and [Vendor Name] levels are just below [All].


- Deepak

Deepak Puri
Microsoft MVP - SQL Server

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


Reply With Quote
  #5  
Old   
ChrisBusch
 
Posts: n/a

Default RE: Topcount within second level - 06-15-2005 , 08:22 AM



Thanks again for you help.

The Top N functionality doesn't seem to work correctly with > 1 level.
When I choose vendor name and show top 10, I get only the top 10
overall rather than the top 10 within each state. More oddly, I don't
actually get the top 10 overall, I get the top 6. If I choose top 5, I get
the top 3. Always seems to be a few short.

Do you have any other suggestions on how to submit this MDX query?
I need to get the results back in a format that could be imported or
copied into Excel.



"ChrisBusch" wrote:

Quote:
I need to return the top 10 vendors within each state on the row axis
along with year on ther column axis.

This query returns the top 10 vendors nationally:

SELECT [TimePeriod].[Year].Members ON COLUMNS,
TOPCOUNT({[Vendor].[Vendor Name].Members},10, [Measures].[Amount]) ON ROWS
FROM APData

This was my attempt to return the top 10 for each state, but fails with a
syntax error.

SELECT [TimePeriod].[Year].Members ON COLUMNS,
[State].[State Code].Members, TOPCOUNT({[Vendor].[Vendor Name].Members},10,
[Measures].[Amount]) ON ROWS
FROM APData

Any help would be greatly appreciated.

Chris Busch
cbusch (AT) blueprintdba (DOT) com


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

Default RE: Topcount within second level - 06-15-2005 , 12:07 PM



Depends on the tools you have available - using SQL Server components,
here's a couple of options:

- You can run MDX like a SQL query with "flattened" results in a DTS
package, if the destination already has columns created to receive the
data (discussed in this NG)

- A Reporting Services Table Report can be built from an MDX query, and
rendered as an Excel or CSV file


- Deepak

Deepak Puri
Microsoft MVP - SQL Server

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

Reply With Quote
  #7  
Old   
ChrisBusch
 
Posts: n/a

Default RE: Topcount within second level - 06-15-2005 , 12:23 PM



What do you mean by "discussed in this NG"?

"Deepak Puri" wrote:

Quote:
Depends on the tools you have available - using SQL Server components,
here's a couple of options:

- You can run MDX like a SQL query with "flattened" results in a DTS
package, if the destination already has columns created to receive the
data (discussed in this NG)

- A Reporting Services Table Report can be built from an MDX query, and
rendered as an Excel or CSV file


- Deepak

Deepak Puri
Microsoft MVP - SQL Server

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


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

Default RE: Topcount within second level - 06-15-2005 , 01:33 PM



Here's an earlier thread from this News Group:

http://groups-beta.google.com/group/...rver.olap/brow
se_thread/thread/8c71a535e7f4e41a/dcf4221a22c7c42f?hl=en#dcf4221a22c7c42
f
Quote:
...
You can actually query an OLAP cube directly from a TransformData task
in DTS. We are running such a query every hour, to detect a timeout
threshold. Here are some details of our scheduled DTS package:

- Source Connection: Microsoft OLE DB Provider for OLAP Services 8.0
(a drop-down option). Properties point to the OLAP Server & DB.

- On the TransformData Source Tab, SQL Query is selected as source.
We have put an MDX query, results get "flattened" to a rowset.
Special SQL syntax is supported, but haven't figured that out yet.

- The Destination Connection is relational OLE DB Provider for SQL
(results filled in pre-defined SQL table). I guess Excel could work
instead here, but you would have to experiment with column mapping.

For the MDX query, a difference from SQL is that, if an empty set is
returned, the result columns are not defined, so check for that first.
...
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.