Distinct Count of Customers in a SCD Type 2 in #DAX

Posted by Marco Russo (SQLBI) on SQL Blog See other posts from SQL Blog or by Marco Russo (SQLBI)
Published on Mon, 09 Apr 2012 20:55:25 GMT Indexed on 2012/04/09 23:41 UTC
Read the original article Hit count: 330

Filed under:
|
|
|

If you have a Slowly Changing Dimension (SCD) Type 2 for your customer and you want to calculate the number of distinct customers that bought a product, you cannot use the simple formula:

Customers := DISTINCTCOUNT( FactTable[Customer Id] ) )

because it would return the number of distinct versions of customers. What you really want to do is to calculate the number of distinct application keys of the customers, that could be a lower number than the number you’ve got with the previous formula. Assuming that a Customer Code column in the Customers dimension contains the application key, you should use the following DAX formula:

Customers := COUNTROWS( SUMMARIZE( FactTable, Customers[Customer Code] ) )

Be careful: only the version above is really fast, because it is solved by xVelocity (formerly known as VertiPaq) engine. Other formulas involving nested calculations might be more complex and move computation to the formula engine, resulting in slower query.

This is absolutely an interesting pattern and I have to say it’s a killer feature. Try to do the same in Multidimensional…

© SQL Blog or respective owner

Related posts about Analysis Services

Related posts about BISM