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

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
mazwro
Helper II
Helper II

calculating churn

Hi, I have a simple table as follows in screenshot:

I want to be able to create a flag to tell if a client is churned - e.g. have seen them purchased in the last 12 months, and I have not idea how to even start it. This I want to use to sum per month  the nr of customers who churned

 

Please help, I am out of ideas.

 

mazwro_0-1718219672464.png

 

2 ACCEPTED SOLUTIONS
Anonymous
Not applicable

Hi @mazwro ,

 

Thanks for the reply from MattAllington .

 

Please try:

 

Create a calculated column that considers a customer churned if they have not made a purchase within the past 12 months of the maximum date in the data set.

IsChurned =
var PY = CALCULATE(
MAX('Table'[order_YM]),
DATESINPERIOD(
'Table'[OrderDate],
MAX('Table'[OrderDate]),
-12,MONTH)
)
RETURN
IF(PY = BLANK(),"Churned", "Active")

 

Create a measure to calculate the number of churned customers:

Count =
CALCULATE(
COUNTROWS('Table'),
'Table'[IsChurned] = "Churned",
ALLEXCEPT('Table', 'Table'[order_YM])
)

vhuijieymsft_0-1718251075324.png

 

If the problem is not solved successfully, I would be grateful if you could provide me with the pbix file or sample data.

 

Remember to remove sensitive data and do not log in to your account in Power BI Desktop when uploading the pbix file.

 

If you have any other questions please feel free to contact me.

 

The pbix file is attached.

 

Best Regards,
Yang
Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

View solution in original post

Anonymous
Not applicable

Hi @mazwro ,

 

Thanks for the reply from MattAllington .

 

This formula returns the churn rate for the last 12 months for the maximum date in your table.

 

If you have any other questions please feel free to contact me.

 

Best Regards,
Yang
Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

View solution in original post

8 REPLIES 8
Anonymous
Not applicable

Hi @mazwro ,

 

Thanks for the reply from MattAllington .

 

Please try:

 

Create a calculated column that considers a customer churned if they have not made a purchase within the past 12 months of the maximum date in the data set.

IsChurned =
var PY = CALCULATE(
MAX('Table'[order_YM]),
DATESINPERIOD(
'Table'[OrderDate],
MAX('Table'[OrderDate]),
-12,MONTH)
)
RETURN
IF(PY = BLANK(),"Churned", "Active")

 

Create a measure to calculate the number of churned customers:

Count =
CALCULATE(
COUNTROWS('Table'),
'Table'[IsChurned] = "Churned",
ALLEXCEPT('Table', 'Table'[order_YM])
)

vhuijieymsft_0-1718251075324.png

 

If the problem is not solved successfully, I would be grateful if you could provide me with the pbix file or sample data.

 

Remember to remove sensitive data and do not log in to your account in Power BI Desktop when uploading the pbix file.

 

If you have any other questions please feel free to contact me.

 

The pbix file is attached.

 

Best Regards,
Yang
Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

Thanks @Anonymous  Yang, this looks like something I can handle, but does it calculate static churn for last 12 months only, or will it work too if I add month split and calculate number of churned per month?

Anonymous
Not applicable

Hi @mazwro ,

 

Thanks for the reply from MattAllington .

 

This formula returns the churn rate for the last 12 months for the maximum date in your table.

 

If you have any other questions please feel free to contact me.

 

Best Regards,
Yang
Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly.
If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

MattAllington
Community Champion
Community Champion

This is how you do it https://www.daxpatterns.com/new-and-returning-customers/



* Matt is an 8 times Microsoft MVP (Power BI) and author of the Power BI Book Supercharge Power BI.
I will not give you bad advice, even if you unknowingly ask for it.

thanks @MattAllington , I am having trouble with this article - I made a script like the following, but i dont know where to take [Date Lost Customer]:

# Lost Customers = 
VAR LastDateLost =
    CALCULATE (
        MAX ( 'nh churned'[OrderDate].[Date] ),
        ALLSELECTED ( 'nh churned'[OrderDate].[Date] )
    )
VAR CustomersWithLostDate =
    CALCULATETABLE (                        -- Prepares a table that 
        ADDCOLUMNS (                        -- for each customer contains 
            VALUES ( 'nh churned'[client_ID] ),  -- the date when they are considered lost 
            "@LostCustomerDate", [Date Lost Customer]
        ),
        ALLEXCEPT ( 'nh churned', 'nh churned'[client_ID] ),
        'nh churned'[OrderDate].[Date] <= LastDateLost
    )
VAR LostCustomers =
    FILTER (                              
        CustomersWithLostDate,          -- Filters the customers
        [@LostCustomerDate]             -- whose lost customer date
            IN VALUES ( 'nh churned'[OrderDate].[Date] )  -- fall within the current period
    )
VAR Result =
    COUNTROWS ( LostCustomers )         -- The count of the lost customers does not
                                        -- use the Sales table (no sales in the period)
RETURN
    Result

If you are going to follow the pattern, you need to do it exactly as shown. It looks like from your formulas that you don't have a calendar table. It's not going to work without that. 

I can tell you that I copied the table structure and formulas, and it worked for me. 



* Matt is an 8 times Microsoft MVP (Power BI) and author of the Power BI Book Supercharge Power BI.
I will not give you bad advice, even if you unknowingly ask for it.

I changed the data to the dates from the date table, still getting an errror with [Date Lost customer] - I dint know where I should get it from

 

# Lost Customers = 
VAR LastDateLost =
    CALCULATE (
        MAX ( 'Dim_Date'[Date] ),
        ALLSELECTED ( 'Dim_Date'[Date] )
    )
VAR CustomersWithLostDate =
    CALCULATETABLE (                        -- Prepares a table that 
        ADDCOLUMNS (                        -- for each customer contains 
            VALUES ( 'nh churned'[client_ID] ),  -- the date when they are considered lost 
            "@LostCustomerDate", [Date Lost Customer]
        ),
        ALLEXCEPT ( 'nh churned', 'nh churned'[client_ID] ),
        'Dim_Date'[Date] <= LastDateLost
    )
VAR LostCustomers =
    FILTER (                              
        CustomersWithLostDate,          -- Filters the customers
        [@LostCustomerDate]             -- whose lost customer date
            IN VALUES ( 'Dim_Date'[Date] )  -- fall within the current period
    )
VAR Result =
    COUNTROWS ( LostCustomers )         -- The count of the lost customers does not
                                        -- use the Sales table (no sales in the period)
RETURN
    Result

Debugging DAX is a structured process. 
1. Set up a matrix and add some relevant data, maybe year and month

2. Add the measures that seem to work and make sure they look correct

3. Add the measure that doesn't work. Read the error message; it's the best insight into what is happening. 



* Matt is an 8 times Microsoft MVP (Power BI) and author of the Power BI Book Supercharge Power BI.
I will not give you bad advice, even if you unknowingly ask for it.

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

Find out what's new and trending in the Fabric community.