Forum Discussion

Mario_Sam's avatar
Mario_Sam
New Member
9 months ago
Solved

DAX Mesure

I have a customer retention report in Power BI and I’m trying to calculate a measure that represents Active Repeat Customers The business logic is a bit complicated and I could not find a working sol...
  • Ahmed-Elfeel's avatar
    9 months ago

    Hi Mario_Sam,

    You can create the following DAX measure to correctly handle the rolling window and the current active condition:

    Active Repeat Customers (90D) =
    VAR MaxSelectedDate =
        MAX ( 'Date'[Date] )
    
    VAR Recent90DaySales =
        CALCULATETABLE (
            Sales,
            DATESINPERIOD (
                'Date'[Date],
                MaxSelectedDate,
                -90,
                DAY
            )
        )
    
    VAR RepeatCustomers =
        FILTER (
            SUMMARIZE (
                Recent90DaySales,
                Sales[CustomerID],
                "OrderCount", COUNTROWS ( Recent90DaySales )
            ),
            [OrderCount] >= 2
        )
    
    VAR ActiveCustomers =
        CALCULATETABLE (
            VALUES ( Sales[CustomerID] ),
            KEEPFILTERS ( 'Date'[Date] )
        )
    
    RETURN
    COUNTROWS (
        INTERSECT ( RepeatCustomers, ActiveCustomers )
    )

     

    if this post helps, then I would appreciate a thumbs up and mark it as the solution to help the other members find it more quickly.