Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
Mario_Sam
New Member

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 solution.

This is the requirement:

 

1-A customer must have made at least 2 purchases within the last 90 days relative to the maximum date selected in the Date slicer. This is considered the rolling window that detects repeat behavior.

 

2-The same customer must also have made at least 1 purchase in the current Date slicer selection. This check ensures that the customer is currently active in the selected period, not someone who only purchased earlier in the 90-day history.

 

3-All slicers and filters must continue to affect the calculation correctly. For example, if Region or Customer Segment is filtered, the result should only consider customers in that filtered region or segment.

 

If the Date slicer selection is October 1 to December 31, then:
-The window for repeat behavior becomes October 2 to December 31 (90 days before max selected date)
-The active condition only checks sales inside the Date slicer selection of October 1 to December 31

A customer should only be counted when both conditions are true:

-They have 2 or more orders within the 90-day rolling window.

-They have at least 1 order within the selected slicer range.

I tried using DISTINCTCOUNT and conditional filters, but I always get wrong results. Either it counts customers who are not active now, or it ignores the slicer completely.

 

How can I write one correct DAX measure that calculates the number of customers who satisfy both rules?

 

Thanks in Advance 🙂

1 ACCEPTED SOLUTION
Ahmed-Elfeel
Solution Sage
Solution Sage

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.

View solution in original post

3 REPLIES 3
Ahmed-Elfeel
Solution Sage
Solution Sage

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.

Hi @Ahmed-Elfeel

Thanks for the answer it worked ,Thank you so much

mdaatifraza5556
Super User
Super User

Hi @Mario_Sam 

Could you please try the below dax

I am assuming you have the dataset in the below format
1. Dim_date table, sales_fact table and dim_customer table

Active_Repeat_Customers =
VAR Max_Visible_Date =
MAX ( 'Date'[Date] ) -- This will return the max date selected in the slicer


VAR Customers_With2PlusIn_90Days =
FILTER (
VALUES ( 'Customer'[CustomerID] ), 
CALCULATE (
DISTINCTCOUNT ( 'Sales'[OrderID] ),
REMOVEFILTERS ( 'Date' ), 
DATESINPERIOD (
'Date'[Date],
Max_Visible_Date ,
-90,
DAY
)
) >= 2
)

 

VAR Active_CustomersIn_Selection =
FILTER (
VALUES ( 'Customer'[CustomerID] ),
CALCULATE (
DISTINCTCOUNT ( 'Sales'[OrderID] )
) >= 1
)


VAR Customers_Meeting_Both =
INTERSECT (
Customers_With2PlusIn_90Days ,
Active_CustomersIn_Selection
)
RETURN
COUNTROWS ( Customers_Meeting_Both )


If this answers your questions, kindly accept it as a solution and give kudos

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

Vote for your favorite vizzies from the Power BI World Championship submissions!

Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.