Quantcast
Channel: SQL Server Analysis Services Forum
Viewing all articles
Browse latest Browse all 2472

MDX distinct count of a combination of columns help

$
0
0

background information related to my problem:


Simplified version of fact and dimension:

date dimension (attributes such as date, month, quarter, half year, year)

UniqueCustomer dimension (basically just one attribute for OperationalCustomerKey)

shop dimension (attributes such asindustry category, geography attributes)

.... other dimension

fact table (TransactionID, DateID, HourGroupID, OperationalCustomerKey, ShopID... other ForeignKey, amount,weights...)

note: weights is at the time of transactions1 customer transactionis equivalent tox number of customers transaction.

fact MeasureGroup aggregate the fact table onto hour group level (e.g.  9-11am is one group) and it has measures: (Transaction Count, amount, Transaction Count, Weighted Transaction Count...)

note: Transaction Count(real measure): count of TransactionID

note: Weighted Transaction Count(real measure): Sum of weights

note: [Weighted Transaction Count]/Transaction Count] is basically the weighted averages of weights

Calculated Member business logic:

Visits:  it is really a distinct count of customer and date combination. e.g. if a customer shopped twice(or more) in a shop (or in itsindustry category etc) on a day, it is only counted as 1 visit in that shop or in that industry category on that day.

WeightedVisitsis visits*weights (i.e. each visits is equivalent to its multiplied weights of visits)

Current method to implement the calculated member:

visits:

COUNT(

   NONEMPTY(

       EXISTING  [Date].[Date].[Date] * EXISTING [UniqueCustomer].[Customer ID].[Customer ID]

        ,[Measures].[Transaction Count]

    )

)

WeightedVisits:

SUM(

   NONEMPTY(

       EXISTING  [Date].[Date].[Date] * EXISTING [UniqueCustomer].[Customer ID].[Customer ID]

        ,[Measures].[Transaction Count]

    )

, [Measures].[Weighted Transaction Count]/[Measures].[Transaction Count]

)

Current problem:

the query, which has above WeightedVisits measure, could run 2-3 minutes but without it the result can be 4 seconds.

or a query which has visits measure could run 30 seconds but without it the result can be 4 seconds.

I can not really store 'visits' in the fact table/view as it changes when you slice by different dimension attribute

Solution?:

  1. no design changes, fine tune MDX?? but not sure how.
  2. no design changes, create another real measure use MeasureExpression "[Measures].[Weighted Transaction Count]/[Measures].[Transaction Count]". this expression was used in the WeightedVisits calculated member. but not sure this will make things faster as it claims to evaluate at the leaf level, could give it a try
  3. introduce another FK?? (e.g. VisitID which is basically artificial key as a result of the combination of DateID and OperationalCustomerKey), but not sure how to get the weighted visits measure (visits measure could be done by assign AggregateFunction Distinctcount on VisitID column)



-- Let us help each other to continuously improve.



Viewing all articles
Browse latest Browse all 2472

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>