mercredi 19 octobre 2016

SSAS Tabular DAX using of IF Statement

I have this query written in SQL:

SELECT
   CustomerId,
   CustomerType,
   CASE WHEN CustomerStatus = 'VIP' 
        THEN CustomerDiscountType
        ELSE NULL
   END AS CustomerDiscountType
FROM Customer

And I would like to write this in DAX query: I know that I can write like this:

EVALUATE
(
    SUMMARIZE
    (
        'Customer',
        'Customer'[CustomerId],
        'Customer'[Type],
        'Customer'[DiscountType],
        "Customer VIP", IF('Customer'[Status] = "VIP", 'Customer'[DiscountType], BLANK())
    )
)

But when I write if condition I need include attribute 'Customer'[DiscountType] in that query too, but I would like to write the column name of that IF statement "DiscountType", but it isn't possible for me like below.

EVALUATE
(
    SUMMARIZE
    (
        'Customer',
        'Customer'[CustomerId],
        'Customer'[Type],
        "DiscountType", IF('Customer'[Status] = "VIP", 'Customer'[DiscountType], BLANK())
    )
)

It failed with this error because of existing DiscountType column: Function 'SUMMARIZE' cannot add column [DiscountType] since it already exists.

Aucun commentaire:

Enregistrer un commentaire