Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
7 years ago
Solved

Perform Calculation at Specified Level - Customer Churn

Hello!   I am new to DAX and looking for any assistance in writing a formula to calculate customer churn. I have one large fact table that contains all data required for this calculation (below). ...
  • Anonymous's avatar
    Anonymous
    7 years ago

    HI Anonymous ,

    You can try to use following measure to check current row status:

    Measure =
    VAR currDate =
        MAX ( Table[Date] )
    VAR LYDate =
        DATE ( YEAR ( currDate ) - 1, MONTH ( currDate ), DAY ( currDate ) )
    VAR LYPurchased =
        CALCULATE (
            COUNTROWS ( Table ),
            FILTER (
                ALLSELECTED ( Table ),
                FORMAT ( Table[Date], "mm/yyyy" ) = FORMAT ( LYDate, "mm/yyyy" )
            ),
            VALUES ( Table[Product Group_cd] ),
            VALUES ( Table[Location_Channel_cd] ),
            VALUES ( Table[AssignedSalesPersonName] )
        )
    VAR prevDate =
        CALCULATE (
            MAX ( Table[Date] ),
            FILTER ( ALLSELECTED ( Table ), [Date] < currDate ),
            VALUES ( Table[Product Group_cd] ),
            VALUES ( Table[Location_Channel_cd] ),
            VALUES ( Table[AssignedSalesPersonName] )
        )
    RETURN
        IF (
            LYPurchased > 0,
            IF (
                FORMAT ( prevDate, "mm/yyyy" ) = FORMAT ( currDate, "mm/yyyy" ),
                "Retained",
                "Lost"
            ),
            "New Customer"
        )
    

    If above not help, please share some sample data for test.

    Regards,

    Xiaoxin Sheng