dbTalk Databases Forums  

MDX: NON EMPTY and HEAD function - how to get first N rows?

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


Discuss MDX: NON EMPTY and HEAD function - how to get first N rows? in the microsoft.public.sqlserver.olap forum.



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

Default MDX: NON EMPTY and HEAD function - how to get first N rows? - 10-27-2004 , 09:21 AM






Hi all,
Here's the plot:
I have MDX queries stored in a DB.
I run those queries and display them in a web page, but I would like to
limit rows returned to, let's say, 100.
So, before running a query, I parse the query and insert Head function for
the ROWS set, e.g.
I turn:
SELECT NON EMPTY {Measures.Members} ON COLUMNS
, NON EMPTY {Dim1.Level.Members} ON ROWS
FROM Cube
into:
SELECT NON EMPTY {Measures.Members} ON COLUMNS
, NON EMPTY Head({Dim1.Level.Members}, 100) ON ROWS
FROM Cube

The problem is that Head filters out first 100 rows whether they are empty
or not, and then NON EMPTY takes only the non-empty ones!
This results in rowcount often less than 100, and if first 100 rows are
empty then it results in an error.

Is there any way to do that?
I mean for the general query, not for a particular one (I know I could use
Filter(Dim1.Level.Members, Not IsEmpty(<SOME MEASURE> ))).

If I could something like: ... Head( NON EMPTY {set}, 100 ) , i.e. apply non
empty filter BEFORE Head function?
Is there a way to achieve this?

Thanks,

Igor



Reply With Quote
  #2  
Old   
Chris Webb
 
Posts: n/a

Default RE: MDX: NON EMPTY and HEAD function - how to get first N rows? - 10-27-2004 , 10:47 AM






Hi Igor,

You might be able to use the NONEMPTYCROSSJOIN function instead. On the plus
side it will give you what you want with faster performance than NON EMPTY;
on the minus side there are some quirks that you have to watch out for - the
fact that it always removes calculated members (unless you have a calculated
measure with the NON_EMPTY_BEHAVIOR set properly), that it doesn't behave
itself with virtual cubes, that the way it works on the Measures dimension
isn't properly documented etc. If you can live with these quirks, then
something like:

SELECT NON EMPTY {Measures.Members} ON COLUMNS
, Head(NONEMPTYCROSSJOIN({Dim1.Level.Members}), 100) ON ROWS
FROM Cube

....should do the trick.

HTH,

Chris



"Igor Mekterovic" wrote:

Quote:
Hi all,
Here's the plot:
I have MDX queries stored in a DB.
I run those queries and display them in a web page, but I would like to
limit rows returned to, let's say, 100.
So, before running a query, I parse the query and insert Head function for
the ROWS set, e.g.
I turn:
SELECT NON EMPTY {Measures.Members} ON COLUMNS
, NON EMPTY {Dim1.Level.Members} ON ROWS
FROM Cube
into:
SELECT NON EMPTY {Measures.Members} ON COLUMNS
, NON EMPTY Head({Dim1.Level.Members}, 100) ON ROWS
FROM Cube

The problem is that Head filters out first 100 rows whether they are empty
or not, and then NON EMPTY takes only the non-empty ones!
This results in rowcount often less than 100, and if first 100 rows are
empty then it results in an error.

Is there any way to do that?
I mean for the general query, not for a particular one (I know I could use
Filter(Dim1.Level.Members, Not IsEmpty(<SOME MEASURE> ))).

If I could something like: ... Head( NON EMPTY {set}, 100 ) , i.e. apply non
empty filter BEFORE Head function?
Is there a way to achieve this?

Thanks,

Igor




Reply With Quote
  #3  
Old   
Igor Mekterovic
 
Posts: n/a

Default Re: MDX: NON EMPTY and HEAD function - how to get first N rows? - 10-28-2004 , 02:26 AM



Thank you Chris for a quick reply!
Unfortunately I have a lot of calculated members, and I'm always quering
against virtual cubes beacuse I'm using dynamic security.
Thanks anyway,
Igor


"Chris Webb" <OnlyForPostingToNewsgroups (AT) hotmail (DOT) com> wrote

Quote:
Hi Igor,

You might be able to use the NONEMPTYCROSSJOIN function instead. On the
plus
side it will give you what you want with faster performance than NON
EMPTY;
on the minus side there are some quirks that you have to watch out for -
the
fact that it always removes calculated members (unless you have a
calculated
measure with the NON_EMPTY_BEHAVIOR set properly), that it doesn't behave
itself with virtual cubes, that the way it works on the Measures dimension
isn't properly documented etc. If you can live with these quirks, then
something like:

SELECT NON EMPTY {Measures.Members} ON COLUMNS
, Head(NONEMPTYCROSSJOIN({Dim1.Level.Members}), 100) ON
ROWS
FROM Cube

...should do the trick.

HTH,

Chris



"Igor Mekterovic" wrote:

Hi all,
Here's the plot:
I have MDX queries stored in a DB.
I run those queries and display them in a web page, but I would like to
limit rows returned to, let's say, 100.
So, before running a query, I parse the query and insert Head function
for
the ROWS set, e.g.
I turn:
SELECT NON EMPTY {Measures.Members} ON COLUMNS
, NON EMPTY {Dim1.Level.Members} ON ROWS
FROM Cube
into:
SELECT NON EMPTY {Measures.Members} ON COLUMNS
, NON EMPTY Head({Dim1.Level.Members}, 100) ON ROWS
FROM Cube

The problem is that Head filters out first 100 rows whether they are
empty
or not, and then NON EMPTY takes only the non-empty ones!
This results in rowcount often less than 100, and if first 100 rows are
empty then it results in an error.

Is there any way to do that?
I mean for the general query, not for a particular one (I know I could
use
Filter(Dim1.Level.Members, Not IsEmpty(<SOME MEASURE> ))).

If I could something like: ... Head( NON EMPTY {set}, 100 ) , i.e. apply
non
empty filter BEFORE Head function?
Is there a way to achieve this?

Thanks,

Igor






Reply With Quote
  #4  
Old   
Chris Webb
 
Posts: n/a

Default Re: MDX: NON EMPTY and HEAD function - how to get first N rows? - 10-28-2004 , 05:33 AM



One last thought - if you are using dynamic security, could you do the non
empty filtering inside your security expression? That's to say that as well
as only showing the members on a dimension that a user has permission to see,
out of these members they only see the non-empty ones. NECJ isn't
unpredictable when it comes to virtual cubes, just a little hard to
understand - with a little experimentation you can probably make it work. See
the following thread for more information
http://groups.google.co.uk/groups?hl...com%26rnum%3D2

Obviously taking this approach has a number of significant drawbacks, but I
could see it working if you were only allowing access to your cube through
the interface where you want to do the non-empty filtering.

Regards,

Chris

"Igor Mekterovic" wrote:

Quote:
Thank you Chris for a quick reply!
Unfortunately I have a lot of calculated members, and I'm always quering
against virtual cubes beacuse I'm using dynamic security.
Thanks anyway,
Igor


"Chris Webb" <OnlyForPostingToNewsgroups (AT) hotmail (DOT) com> wrote in message
news:8EE1FB58-9632-4D9F-92D4-F7E16CA7E8B2 (AT) microsoft (DOT) com...
Hi Igor,

You might be able to use the NONEMPTYCROSSJOIN function instead. On the
plus
side it will give you what you want with faster performance than NON
EMPTY;
on the minus side there are some quirks that you have to watch out for -
the
fact that it always removes calculated members (unless you have a
calculated
measure with the NON_EMPTY_BEHAVIOR set properly), that it doesn't behave
itself with virtual cubes, that the way it works on the Measures dimension
isn't properly documented etc. If you can live with these quirks, then
something like:

SELECT NON EMPTY {Measures.Members} ON COLUMNS
, Head(NONEMPTYCROSSJOIN({Dim1.Level.Members}), 100) ON
ROWS
FROM Cube

...should do the trick.

HTH,

Chris



"Igor Mekterovic" wrote:

Hi all,
Here's the plot:
I have MDX queries stored in a DB.
I run those queries and display them in a web page, but I would like to
limit rows returned to, let's say, 100.
So, before running a query, I parse the query and insert Head function
for
the ROWS set, e.g.
I turn:
SELECT NON EMPTY {Measures.Members} ON COLUMNS
, NON EMPTY {Dim1.Level.Members} ON ROWS
FROM Cube
into:
SELECT NON EMPTY {Measures.Members} ON COLUMNS
, NON EMPTY Head({Dim1.Level.Members}, 100) ON ROWS
FROM Cube

The problem is that Head filters out first 100 rows whether they are
empty
or not, and then NON EMPTY takes only the non-empty ones!
This results in rowcount often less than 100, and if first 100 rows are
empty then it results in an error.

Is there any way to do that?
I mean for the general query, not for a particular one (I know I could
use
Filter(Dim1.Level.Members, Not IsEmpty(<SOME MEASURE> ))).

If I could something like: ... Head( NON EMPTY {set}, 100 ) , i.e. apply
non
empty filter BEFORE Head function?
Is there a way to achieve this?

Thanks,

Igor







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.