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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply

RETENTION

Hi Fam,


I am working on a retention chart. The idea is to know on a daily basis how many customers are churned and retained. 
The logic is: 

Customers who ordered between day-60 to day-31 ago from today and still order between day-30 to day-1 (today) are considered retained, they are churned otherwise. 

Today is day 1
Yesterday is day 2
9 July 2023 is day 30 
8 July 2023 is day 31
9 June 2023 is day 60


In my orders table, I have the following columns: 

1. order_id (unique)
2. customer_id (unique) 
3. time_pickup_date

The thing is, I want to start day 1 based on the date filter I set.  

Screenshot 2023-08-08 113941.png



Then, I want to visualize it where x-axis is the date, y-axis is count of customers (distinct). Legend is churn and retained. 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Andrew_na_lang ,

Please have a try.

Retention =
VAR SelectedDateRange = SELECTEDVALUE('Date'[Date])
VAR Today = TODAY()
VAR DaysBetween = DATEDIFF(EARLIER('Orders'[time_pickup_date]), Today, DAY)
VAR RetainedCustomers =
    CALCULATE(
        DISTINCTCOUNT('Orders'[customer_id]),
        FILTER(
            'Orders',
            DaysBetween >= 31
                && DaysBetween <= 60
                && 'Orders'[time_pickup_date] >= SelectedDateRange - 30
                && 'Orders'[time_pickup_date] <= SelectedDateRange - 1
        )
    )
VAR ChurnedCustomers =
    CALCULATE(
        DISTINCTCOUNT('Orders'[customer_id]),
        FILTER(
            'Orders',
            DaysBetween >= 31
                && DaysBetween <= 60
                && ('Orders'[time_pickup_date] < SelectedDateRange - 30 || 'Orders'[time_pickup_date] > SelectedDateRange - 1)
        )
    )
RETURN
    SWITCH(
        TRUE(),
        RetainedCustomers = 0 && ChurnedCustomers = 0, BLANK(),
        RetainedCustomers = 0, "Churned",
        ChurnedCustomers = 0, "Retained",
        RetainedCustomers, "Retained",
        "Churned"
    )

 

How to Get Your Question Answered Quickly 

 

If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .

 

Best Regards
Community Support Team _ Rongtie

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

 

View solution in original post

1 REPLY 1
Anonymous
Not applicable

Hi @Andrew_na_lang ,

Please have a try.

Retention =
VAR SelectedDateRange = SELECTEDVALUE('Date'[Date])
VAR Today = TODAY()
VAR DaysBetween = DATEDIFF(EARLIER('Orders'[time_pickup_date]), Today, DAY)
VAR RetainedCustomers =
    CALCULATE(
        DISTINCTCOUNT('Orders'[customer_id]),
        FILTER(
            'Orders',
            DaysBetween >= 31
                && DaysBetween <= 60
                && 'Orders'[time_pickup_date] >= SelectedDateRange - 30
                && 'Orders'[time_pickup_date] <= SelectedDateRange - 1
        )
    )
VAR ChurnedCustomers =
    CALCULATE(
        DISTINCTCOUNT('Orders'[customer_id]),
        FILTER(
            'Orders',
            DaysBetween >= 31
                && DaysBetween <= 60
                && ('Orders'[time_pickup_date] < SelectedDateRange - 30 || 'Orders'[time_pickup_date] > SelectedDateRange - 1)
        )
    )
RETURN
    SWITCH(
        TRUE(),
        RetainedCustomers = 0 && ChurnedCustomers = 0, BLANK(),
        RetainedCustomers = 0, "Churned",
        ChurnedCustomers = 0, "Retained",
        RetainedCustomers, "Retained",
        "Churned"
    )

 

How to Get Your Question Answered Quickly 

 

If it does not help, please provide more details with your desired output and pbix file without privacy information (or some sample data) .

 

Best Regards
Community Support Team _ Rongtie

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

 

 

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Fabric Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.