views:

353

answers:

1

Hi folks, im pretty newbie at mdx sintaxys.

I have the next requirement that i need to be able to solve it using mdx, if its possible. I need to show the number of SALE transactions which amout value is greater than "X" , the number of SALE transactions which amount value is less than "Y" , the number of CREDIT transactions which amout value is greater than "Z". and so on. my cube has a measure called "amount" with a aggregate function "sum" and transactionNumber with a agregate function "count" and a time dimesion, transactionType dimension and others.

the thing is, that X, Y and Z are dynamics values and configured by users, i need to read those values, build the query and execute it vía xmla.

I'm wating a resultset as the next one

                  Greater than > 200 USD       less than < 0.10       total

          SALE            150                         10               300
          CREDIT          200                         30               600
          VODI            10                           2                60

any help you can provide me, i'll appreciate it

+2  A: 

This would only be possible if you had an attribute that was at the transaction level, otherwise your measures will be pre-aggregated to a higher level.

If you did have something like a [Transaction ID] attribute, you could write a query like the following.

WITH 
  MEMBER Measures.[Greater than 200 USD] as 
    SUM(Filter([Transaction ID].[Transaction ID].[Transaction ID], Measures.Amount > 200)
       , Measures.Count)
  MEMBER Measures.[Less than 0.10 USD] as 
    SUM(Filter([Transaction ID].[Transaction ID].[Transaction ID], Measures.Amount > 200)
       , Measures.Count)
  MEMBER Measures.Total as Measures.Count
SELECT
  {Measures.[Greater than 200 USD]
    ,Measures.[Less than 0.10 USD]
    ,Measures.[Total]} ON columns
 , [Transaction Type].[Transaction Type].[Transaction Type] ON Rows
FROM <Cube>
Darren Gosbell
Thank you darren for your quick answer. I translated you pseudo-query but i didn't get the right results, i just get one (1) in all cells. if i check the database, there are more than one result that match with the filter condition. So, i dont know what might be wrong.PART OF MY CALCULATED MEMBERS LOOK LIKE:with member [Measures].[Greater than 200 USD] as 'Sum(Filter({[TransactionId].[All TransactionIds]}, ([Measures].[Amount] > 200.0)), Count({[Measures].[Amount]}))'
rfders
Your translation is not quite right, you are counting the "All transactions" member (of which there is only 1). What you want to count are the members of the TransactionId level, within the TransactionId hierarchy, within the TransactionId dimension (hence the triple reference) eg. With member [Measures].[Greater than 200 USD] as 'Sum(Filter({[TransactionId].[TransactionIds].[TransactionIds]}, ([Measures].[Amount] > 200.0)), Count({[Measures].[Amount]}))'
Darren Gosbell
what about the performace, i already implemeted your solutions but the performace its really bad, my fact table has aprox 1MM of records. there any consideration that i need to take care of ??. cheers.
rfders
yes, performance the performance of this sort of query is not likely to be all that good. Querying arbitrary ranges is just not something that OLAP handles well. MDX is great for aggregating data, SQL is probably faster at scanning lots of data (which is what you are doing here)
Darren Gosbell