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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
FearDerBeard
Frequent Visitor

Calculate retained customers over time

I have a transactional table that records a customer record over time.  Customers come in and out over time and I'd like to calculate how many are kept from some starting point.

 

For example, if you arrive in period 1, did you return in period 2 or subsequent periods.

Table:

CustomerIDPeriodID
12341
13451
25671
36781
48901
57891
68901
54211
12342
13452
25672
11112
22222
68902
36783
11113

 

Outcome:

First PeriodPeriodRetained Customers% Retained
118100%
12338%
13113%

 

I tried a bi-directional join through a table of all unique customerid's and a copy of the original table but the results were incorrect.  Hope this makes sense.  Thanks.

1 ACCEPTED SOLUTION
v-yulgu-msft
Microsoft Employee
Microsoft Employee

Hi @FearDerBeard,

 

In your sceario, do you only need to count the retained customers start from PeriodId 1?

 

If so, please refer to below DAX formula to see whether it works for you.

Column1 =
LOOKUPVALUE (
    'retained over time'[CustomerID],
    'retained over time'[CustomerID], 'retained over time'[CustomerID],
    'retained over time'[PeriodID], 'retained over time'[PeriodID] - 1
)

Column2 =
IF (
    'retained over time'[PeriodID] = 1,
    CALCULATE (
        DISTINCTCOUNT ( 'retained over time'[CustomerID] ),
        FILTER ( 'retained over time', 'retained over time'[PeriodID] = 1 )
    ),
    CALCULATE (
        COUNT ( 'retained over time'[Column1] ),
        ALLEXCEPT ( 'retained over time', 'retained over time'[PeriodID] )
    )
)

Regards,
Yuliana Gu

Community Support Team _ Yuliana Gu
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

2 REPLIES 2
v-yulgu-msft
Microsoft Employee
Microsoft Employee

Hi @FearDerBeard,

 

In your sceario, do you only need to count the retained customers start from PeriodId 1?

 

If so, please refer to below DAX formula to see whether it works for you.

Column1 =
LOOKUPVALUE (
    'retained over time'[CustomerID],
    'retained over time'[CustomerID], 'retained over time'[CustomerID],
    'retained over time'[PeriodID], 'retained over time'[PeriodID] - 1
)

Column2 =
IF (
    'retained over time'[PeriodID] = 1,
    CALCULATE (
        DISTINCTCOUNT ( 'retained over time'[CustomerID] ),
        FILTER ( 'retained over time', 'retained over time'[PeriodID] = 1 )
    ),
    CALCULATE (
        COUNT ( 'retained over time'[Column1] ),
        ALLEXCEPT ( 'retained over time', 'retained over time'[PeriodID] )
    )
)

Regards,
Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Greg_Deckler
Super User
Super User

Perhaps something along the lines of this:

 

Customers Retained = IF(SUM(Customers[PeriodID])=1,COUNT([PeriodID]),COUNT([PeriodID]) - CALCULATE(COUNT([PeriodID]),ALL(Customers[CustomerID]),FILTER(Customers,[PeriodID]=[PeriodID]-1)))

That isn't the entire solution because it doesn't match customer id's but may get you close.

 



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

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

June 2025 community update carousel

Fabric Community Update - June 2025

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