Handle DistinctCount counts NULL

Analysis Services handles NULL and 0 as the same thing, and 0 would normally be considered something worth counting, whereas NULL wouldn’t.

When you count for example the sex of  distinct customer, you dont’ want to count who not have sex, (the null value). you have to do these:

  1. Create a new column on the fact table that indicates whether the field we want to distinctcount is null. To do this we add a new column and give it the fixed value 1 when the Attribute is empty.
  2. Create three measures
    • DistinctOriginal: Standard measure, DistinctCount on attribute, hidden measure
    • IsAttributeNumberNull:Standard measure, MAX on isAttibuteNull, hidden measure
    • DistinctAttribute: Calculated measure, Formula: DistinctOriginal – IsAttributeNumberNull

And that’s it, use the new calculated measure for a distinct count that does not count NULLs.

Annunci

Rispondi

Inserisci i tuoi dati qui sotto o clicca su un'icona per effettuare l'accesso:

Logo WordPress.com

Stai commentando usando il tuo account WordPress.com. Chiudi sessione / Modifica )

Foto Twitter

Stai commentando usando il tuo account Twitter. Chiudi sessione / Modifica )

Foto di Facebook

Stai commentando usando il tuo account Facebook. Chiudi sessione / Modifica )

Google+ photo

Stai commentando usando il tuo account Google+. Chiudi sessione / Modifica )

Connessione a %s...