Showing posts with label newbie. Show all posts
Showing posts with label newbie. Show all posts

Monday, March 19, 2012

MDX-why the null result is missing?

Hi,friends, this is a newbie quetion about MDX.

I just write the MDX below:

select KPIValue("ADTD")on rows, {[Time].[TimeLevel].[Year].&[2007] } on columns from [TargetCube] where [Agent].[AgentMember].&[2]

And this return the result very well:

2007

ADTD 128

Then I change the MDX to this:

select KPIValue("ADTD")on rows, {[Time].[TimeLevel].[Year].&[2007],[Time].[TimeLevel].[Year].&[2008]} on columns from [TargetCube] where [Agent].[AgentMember].&[2]

And this return the same result:

2007

ADTD 128

It's very strange to me. Because there is no 2008's record in the Cube, I think the result ought to be :

2007 2008

ADTD 128 0

But why the result just makes the 2008's column Missing?

Thanks!

What is the MDX formula for KPIValue("ADTD"); and can you reproduce this problem with a KPI query in Adventure Works?|||

the MDX formula for KPIvalue("ADTD") is just refer to an Measure which Count the records of the facttable. I think this is not the answer. You could reproduce this problem with a KPI query in Adventrue Works.

And not only the KPI query, but every MDX query is like this. It looks like it's a common law of the MDX. You could have a simple test like this:

select ([Measures].Angel) on rows, {[Time].[TimeLevel].[Year].&[2008]} on columns from [Cube] where [Agent].[AgentLevel].&[2]

Because there is no 2008's records in the facttable, and you will get the result like this:

A

not like this:

2008

A 0

but I really want to get the second result, because if there is no 2008's records, the right answer of the query ought to be 0.

Please have a test based on the Adventrue Works., thanks!

|||

"because if there is no 2008's records, the right answer of the query ought to be 0" - well, the "right" answer depends on the scenario, but maybe applying CoalesceEmpty() will help you, like:

With

Member [Measures].[OrdersNoNull] as

CoalesceEmpty([Measures].[Order Count],0)

select

{[Date].[Calendar].[Month].&[2004]&[7],

[Date].[Calendar].[Month].&[2004]&Music} on 0,

{[Measures].[Order Count],

[Measures].[OrdersNoNull]} on 1

from [Adventure Works]

-

July 2004 August 2004
Order Count 976 (null)
OrdersNoNull 976 0

|||

Puri , you don't catch my mean. Use your example, you get the answer:

July 2004 August 2004
Order Count 976 (null)

And this is also what I want. But I got the answer:

July 2004

Order Count 976

The Agust 2004 column is missing. That's my problem. I run the MDX , and return a result without August 2004 column. If the result is (null), that's OK, that's what exactly I want. My problem is not to change (null) to 0. My problem is just the column is missing.

Thanks.

|||What tool are using to run your MDX query? My results came from Management Studio - so are you saying that you don't get the same results, when you run the above query in Management Studio?|||

Yes, me in Management Studio too. And I also tried the ADOMD.net, the same result.

You could try to only select one Measure like me have done.

Thanks.

|||To be clear, could you post an actual Adventure Works query, with the results you get in Management Studio, so that others can try to reproduce your problem?|||

eh,you could test it at a very simple way.

Just in the MDX you select a Time not existed. For example, if there is from 2000 to 2008's data in the cube, and no 2050 's data in the cube. Then you JUST select the 2050's in the MDX query. Then you will get the result I said. the 2050's column is missing, not the (NULL).

|||

I think it sounds very reasonable though? You dont have any record of the year you specified in your MDX query, then of course the result retured with nothing on that year?

With best regards,

Yours sincerely,

MDX-why the null result is missing?

Hi,friends, this is a newbie quetion about MDX.

I just write the MDX below:

select KPIValue("ADTD")on rows, {[Time].[TimeLevel].[Year].&[2007] } on columns from [TargetCube] where [Agent].[AgentMember].&[2]

And this return the result very well:

2007

ADTD 128

Then I change the MDX to this:

select KPIValue("ADTD")on rows, {[Time].[TimeLevel].[Year].&[2007],[Time].[TimeLevel].[Year].&[2008]} on columns from [TargetCube] where [Agent].[AgentMember].&[2]

And this return the same result:

2007

ADTD 128

It's very strange to me. Because there is no 2008's record in the Cube, I think the result ought to be :

2007 2008

ADTD 128 0

But why the result just makes the 2008's column Missing?

Thanks!

What is the MDX formula for KPIValue("ADTD"); and can you reproduce this problem with a KPI query in Adventure Works?|||

the MDX formula for KPIvalue("ADTD") is just refer to an Measure which Count the records of the facttable. I think this is not the answer. You could reproduce this problem with a KPI query in Adventrue Works.

And not only the KPI query, but every MDX query is like this. It looks like it's a common law of the MDX. You could have a simple test like this:

select ([Measures].Angel) on rows, {[Time].[TimeLevel].[Year].&[2008]} on columns from [Cube] where [Agent].[AgentLevel].&[2]

Because there is no 2008's records in the facttable, and you will get the result like this:

A

not like this:

2008

A 0

but I really want to get the second result, because if there is no 2008's records, the right answer of the query ought to be 0.

Please have a test based on the Adventrue Works., thanks!

|||

"because if there is no 2008's records, the right answer of the query ought to be 0" - well, the "right" answer depends on the scenario, but maybe applying CoalesceEmpty() will help you, like:

With

Member [Measures].[OrdersNoNull] as

CoalesceEmpty([Measures].[Order Count],0)

select

{[Date].[Calendar].[Month].&[2004]&[7],

[Date].[Calendar].[Month].&[2004]&Music} on 0,

{[Measures].[Order Count],

[Measures].[OrdersNoNull]} on 1

from [Adventure Works]

-

July 2004 August 2004
Order Count 976 (null)
OrdersNoNull 976 0

|||

Puri , you don't catch my mean. Use your example, you get the answer:

July 2004 August 2004
Order Count 976 (null)

And this is also what I want. But I got the answer:

July 2004

Order Count 976

The Agust 2004 column is missing. That's my problem. I run the MDX , and return a result without August 2004 column. If the result is (null), that's OK, that's what exactly I want. My problem is not to change (null) to 0. My problem is just the column is missing.

Thanks.

|||What tool are using to run your MDX query? My results came from Management Studio - so are you saying that you don't get the same results, when you run the above query in Management Studio?|||

Yes, me in Management Studio too. And I also tried the ADOMD.net, the same result.

You could try to only select one Measure like me have done.

Thanks.

|||To be clear, could you post an actual Adventure Works query, with the results you get in Management Studio, so that others can try to reproduce your problem?|||

eh,you could test it at a very simple way.

Just in the MDX you select a Time not existed. For example, if there is from 2000 to 2008's data in the cube, and no 2050 's data in the cube. Then you JUST select the 2050's in the MDX query. Then you will get the result I said. the 2050's column is missing, not the (NULL).

|||

I think it sounds very reasonable though? You dont have any record of the year you specified in your MDX query, then of course the result retured with nothing on that year?

With best regards,

Yours sincerely,

MDX:time between fatcs / time spent in a state

Hi all

I am an MDX newbie and it happens i have to do immediately with a query that seems (to me) pretty unorthodox.

The fact table i have is made up of the following entities: StateMachineId, StateId, TransitionDateTime.
In fact, i have several State Machines that can find themselves in different states and i log in a DB the time of their transitions and the new state.
I need to generate reports mostly based on the time spent in each state and i have no clue on what is the best way to do that in mdx.
In sql, what i did was to join this FactTable (FT1) with itself (FT2) ON StateMachineId adding the condition that FT2.TransitionDateTime BETWEEN FT1.TransitionDateTime AND FT1.TransitionDateTime + SomeTimeInterval , in this way i narroewed the size of the join. At this point, i took the row from FT2 with the lesser TransitionDateTime .
All this works perfectly, but it is akward and pretty slow. Another downside is that some longer transitions (those longer than SomeTimeInterval) are excluded.
I think working with MDX could be better but, as i stated before, i am new in this field.
Do you have some ideas to create a suitable cube for these queries?

Thank You So Much

Best regards

Wentu
It's me again

I found this SQL solution:

Code Snippet

with modnums as (
select *, row_number() over (order by StateMachineId, TransitionDateTime) as rn
from FactTable
)
select m_this.StateMachineId, m_this.TransitionDateTime, m_next.StateId, m_next.TransitionDateTime, m_this.StateId, datediff(ms,m_this.TransitionDateTime, m_next.TransitionDateTime) elapsedTime
from
modnums m_this
inner join
modnums m_next
on m_next.rn = m_this.rn + 1
and m_this.StateMachineId = m_next.StateMachineId


It's working very well (Thankx to Rob Farley for this) .
Now, i would like to use it in Analysis Services but the "OVER" is not allowed in Named Queries. Any Idea on how to write this query in MDX ?

Thankx again

Wentu

Monday, February 20, 2012

MDX Newbie : Average Population Size

SQL 2005 SSAS

I have a table of daily population of vessels by category. (We're a shipping company so population is number of vessels, but the MDX could equally apply to any population).

I need to get the MDX to give average population size over a period and category. Total population was easy : it's just COUNT DISTINCT vesselname.

But average needs to be something like :
(COUNT DISTINCT DAILY vesselname for given category) averaged over the time period.

Can anybody point me in the right direction to get the MDX for this?

Thanks

Heres' a sample Adventure Works query which computes the average daily customer count for various product categories, in Q4 2003 ([Measures].[Customer Count] is a distinct count measure on the CustomerKey of the Internet Sales fact table):

>>

With

Member [Measures].[AvgDailyCustomers] as

Avg(Existing [Date].[Date].[Date],

[Measures].[Customer Count])

select {[Measures].[Internet Order Quantity],

[Measures].[Internet Sales Amount],

[Measures].[Customer Count],

[Measures].[AvgDailyCustomers]} on 0,

Non Empty [Product].[Category].Members on 1

from [Adventure Works]

where [Date].[Calendar].[Calendar Quarter].&[2003]&[4]

Internet Order Quantity Internet Sales Amount Customer Count AvgDailyCustomers
All Products 13,590 $4,009,218.46 5,090 60
Accessories 9,009 $175,035.18 4,212 49
Bikes 2,378 $3,751,923.02 2,313 26
Clothing 2,203 $82,260.26 1,745 20

>>