Showing posts with label mdx. Show all posts
Showing posts with label mdx. Show all posts

Monday, March 26, 2012

How to apply an MDX filter that doesn't affect roll-up?

Take the Employee dimension of Adventure Works Cube. I want to see a list of all Male Employees and the total Reseller-Sales they supervise. My MDX query looks like this

Select [Measures].[Reseller Sales-Sales Amount] on Columns,
non empty [Employee].[Employees].AllMembers on Rows
from [Analysis Services Tutorial]
where [Employee].[Gender].&[M]

and I get a result of

Reseller Sales-Sales Amount
All Employees $44,244,815.17
Ken J. Sánchez $44,244,815.17
Brian S. Welcker $44,244,815.17
Ranjit R. Varkey Chudukatil $4,509,888.93
Stephen Y. Jiang $39,562,401.78
David R. Campbell $3,729,945.35
Garrett R. Vargas $3,609,447.22
Jos Edvaldo. Saraiva $5,926,418.36
Michael G. Blythe $9,293,903.01
Shu K. Ito $6,427,005.56
Stephen Y. Jiang $1,092,123.86
Tete A. Mensa-Annan $2,312,545.69
Tsvi Michael. Reiter $7,171,012.75
Syed E. Abbas $172,524.45

ok so it gave me all the male employees, which is good, but the sales amounts are incorrect, it is only summing

the sales of the male underlings. Ken J. Sánchez actually has 80 million in sales under him, Stephen Y. Jiang has 63 million, etc... The Cube is not counting the female underlings sales. How do I include everything in the roll-ups, but only return the male supervisors?

Thanks

Todd Wilder

Select [Measures].[Reseller Sales-Sales Amount] on Columns,
non empty

Exists(

[Employee].[Employees].AllMembers

,[Employee].[Gender].&[M]

) on Rows
from [Analysis Services Tutorial]

That should only show male employees on rows, but the totals should reflect all employees under them.|||

There seems to be a slight twist to this, since Employee is a parent-child dimension. Apparently, using the parent-child hierarchy, a member can "exist" with an attribute like [Employee].[Gender].&[M] if any of its descendants are male. But a member of the key attribute hierarchy works as with regular dimensions. So LinkMember() can be used to map key attribute members to the corresponding parent-child members, like:

Select [Measures].[Reseller Sales Amount] on Columns,
non empty Generate(exists([Employee].[Employee].[Employee],
[Employee].[Gender].&[M]),
{LinkMember([Employee].[Employee].CurrentMember,
[Employee].[Employees])}) on Rows
from [Adventure Works]

In this case, there is a discrepancy between the 2 queries of a single (non empty) member - Amy E. Alberts (female):

Select [Measures].[Reseller Sales Amount] on Columns,
non empty exists([Employee].[Employees].Members,
[Employee].[Gender].&[M]) -
Generate(exists([Employee].[Employee].[Employee],
[Employee].[Gender].&[M]),
{LinkMember([Employee].[Employee].CurrentMember,
[Employee].[Employees])})on Rows
from [Adventure Works]
--
Reseller Sales Amount
All Employees $80,450,596.98
Amy E. Alberts $15,535,946.26

Monday, March 12, 2012

How to add parameters to a MDX query in RS 2005?

I'm currently struggling with parameters when doing reports based on SSAS
2005 in RS 2005.
How do I add a new parameter to an MDX query, after having built the query
using the wysiwig query builder? I could probably start all over again to
use the query builder, but I can't figure out how to create semi-dynamic
queries like I did with RS 2000 / AS 2000.
And is there a way to choose if a parameter should be multivalue when adding
it as a parameter?
Any good books focusing on Reporting Services and Analysis Services 2005?
Most of them focus on SQL based reports.
Kaisa M. Lindahl LervikHope you have tried puting "@." to the parameters this is basics and go to
report parameter from menu and can define multi value.
A book from "Brian Larson" of SSRS and SS BI is good book to start with and
your online help and samples are best resources for learning.
Amarnath
"Kaisa M. Lindahl Lervik" wrote:
> I'm currently struggling with parameters when doing reports based on SSAS
> 2005 in RS 2005.
> How do I add a new parameter to an MDX query, after having built the query
> using the wysiwig query builder? I could probably start all over again to
> use the query builder, but I can't figure out how to create semi-dynamic
> queries like I did with RS 2000 / AS 2000.
> And is there a way to choose if a parameter should be multivalue when adding
> it as a parameter?
> Any good books focusing on Reporting Services and Analysis Services 2005?
> Most of them focus on SQL based reports.
> Kaisa M. Lindahl Lervik
>
>|||I had problems with the whole strtomember syntax. Just making a parameter
didn't put this new parameter into the query, probably because I'd gone from
the editor to hand editing the query, and I couldn't figure out the syntax
of a new parameter.
Anyway, I found out how to make dynamic mdx queries the old way*. I'll check
out the book by Brian Larson, there's probably a more modern way of making
mdx based reports than the old school way I'm used to. ;)
*= Make a new data source with OLE DB instead of Analysis Services, and then
connect it to Analysis Services 9.0. Gives you back the good old text only
editor, which I prefer right now.
Kaisa M: Lindahl Lervik
"Amarnath" <Amarnath@.discussions.microsoft.com> wrote in message
news:FFF7458A-F34C-4CC7-8CA0-55C59B8C0106@.microsoft.com...
> Hope you have tried puting "@." to the parameters this is basics and go to
> report parameter from menu and can define multi value.
> A book from "Brian Larson" of SSRS and SS BI is good book to start with
> and
> your online help and samples are best resources for learning.
> Amarnath
> "Kaisa M. Lindahl Lervik" wrote:
>> I'm currently struggling with parameters when doing reports based on SSAS
>> 2005 in RS 2005.
>> How do I add a new parameter to an MDX query, after having built the
>> query
>> using the wysiwig query builder? I could probably start all over again to
>> use the query builder, but I can't figure out how to create semi-dynamic
>> queries like I did with RS 2000 / AS 2000.
>> And is there a way to choose if a parameter should be multivalue when
>> adding
>> it as a parameter?
>> Any good books focusing on Reporting Services and Analysis Services 2005?
>> Most of them focus on SQL based reports.
>> Kaisa M. Lindahl Lervik
>>

Sunday, February 19, 2012

How to accomplish (Date)Between in MDX?

Hi all,

I thought it would be simple, but it turned out to be to difficult for me. I have the next problem;

I want to get the salesinfo of the latest 30 days, It should show me all the data between _Now() minus 30 days and Now()_
Has anyone any Idea how this could be accomplished?

Regards.

The main trick here is how to map the result of the now() function to a particular member in the date dimension.

Could you tell us how your Date dimension is structured and give some examples of what you are using for the key and name for the day attribute.

Also, are you sure that you want to use now() - another common approach would be to find the last day with data and then go back 30 days. A lot of data warehouses get re-populated overnight, so they are always lagging atleast one day behind the live data.

|||

Thanks for your reply Darren,

My Time Dimension is structured as follow:
Year (1-1-2005, 1-1-2006)
Quarter (1-1-2006, 1-4-2006)
Month (1-1-2006, 1-2-2006)
Week (1-1-2006, 8-1-2006)
PKDate (1-1-2006, 2-1-2006)- this is the Key

The reason why I want to use Now() is that the Time Table in the Datamart has fixed dates until the year 2008. And I'm not able to change this because I'm only working on reporting, and we work with subscription which have an enddate in 2007 or 2008.

Hopely this clearifies it a little bit.

Regards.

|||

I'm still making some assumptions, but I think you could set up a calculated member roughly like the following.

Create member CurrentCube.Time.PKDate.Today as StrToMember("[Time].[PKDate].[" + format(now(),"d-m-yyyy") + "]")

Then your measure for the last 30 days would be:

Create member CurrentCube.measures.Last30Days as Aggregate([Time].[PKDate].Today:[Time].[PKDate].Today.lag(30))