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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Identifying loss customer after 4 month no purchase

Hi,

 

I would like to create a measure or new column that identifies a lost customer. 

A lost customer is defined as a customer that haven't made a purchase for 4 months.

If after 4 months the customer makes a purchase again it is not a lost customer anymore.

 

I have had a simular topic regarding new customers, which can be found here

 

I am using the follwing data:

(Last column in red is the desired column)

CompanyCompany NrProductPurchase dateValueLoss customer
Company A1111Soda12-1-2018100Loss
Company A1111Soda24-2-201870Loss
Company A1111Beer8-3-2018145Loss
Company A1111Water12-3-2018293Loss
Company B223311Beer12-5-201780 
Company B223311Beer13-6-2017200 
Company B223311Beer24-6-201740 
Company B223311Water24-5-201830 
Company B223311Soda12-6-201860 
Company B223311Soda31-7-201850 
Company B223311Beer2-8-2018400 
Company C33229153Soda22-2-201723Loss
Company C33229153Beer25-5-201751Loss
Company C33229153Soda12-8-2017175Loss
Company C33229153Water23-11-201746Loss
Company C33229153Soda7-1-201834Loss
Company C33229153Beer16-2-201825Loss
      

 

Furtheremore I have to be able to include or exclude customers manually.

Like the DAX for new customers has as well:

 

New Customer =
VAR CurrentYear = 2017
VAR PriorYear = CurrentYear - 1
VAR FirstPurchaseCurrentYear =
    CALCULATE (
        MIN ( Table1[Date] ),
        FILTER (
            ALLEXCEPT ( Table1, Table1[Company] ),
            OR (
                YEAR ( Table1[Date] ) = CurrentYear,
                AND ( YEAR ( Table1[Date] ) = PriorYear, MONTH ( Table1[Date] ) = 12 )
            )
        )
    )
VAR LastPurchasebeforeCurrentYear =
    CALCULATE (
        MAX ( Table1[Date] ),
        FILTER (
            ALLEXCEPT ( Table1, Table1[Company] ),
            Table1[Date] < DATE ( PriorYear, 12, 1 )
        )
    )
VAR SalesGap =
    DATEDIFF ( LastPurchasebeforeCurrentYear, FirstPurchaseCurrentYear, MONTH )
RETURN
    IF (
        AND (
            SalesGap > 12
                || SalesGap = BLANK (),
            OR (
                YEAR ( Table1[Date] ) = CurrentYear,
                AND ( YEAR ( Table1[Date] ) = PriorYear, MONTH ( Table1[Date] ) = 12 )
            )
        ),
        "New Customer"
    )

Hope you can help me.

 

If any questions please do not hesitate to ask!

1 ACCEPTED SOLUTION
edhans
Super User
Super User

See if this will help get you on the right track.

First, I calculated the maximum purchase date for each customer:

 

Max Sales Date = 
CALCULATE(
    MAX(Sales[Purchase date]),
    ALLEXCEPT(Sales,Sales[Company])
)

Then I calculated the duration in months from today's date to [Max Sales Date] above:

 

 

Duration = 
DATEDIFF(
    [Max Sales Date],
    TODAY(),
    MONTH
)

Then I made a simple IF() comparison:

Lost Customer = 
IF(
    [Duration] > 4,
    "Lost",
    BLANK()
)

That gave me a table that looks like this:

image.png

 

You can hide the intermediate measures, or combine them into one big complex measure if desired.

See this file.



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

View solution in original post

4 REPLIES 4
v-jiascu-msft
Employee
Employee

Hi @Anonymous,

 

Could you mark the proper answer as a solution please?

 

Best Regards,

Dale

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

See if this will help get you on the right track.

First, I calculated the maximum purchase date for each customer:

 

Max Sales Date = 
CALCULATE(
    MAX(Sales[Purchase date]),
    ALLEXCEPT(Sales,Sales[Company])
)

Then I calculated the duration in months from today's date to [Max Sales Date] above:

 

 

Duration = 
DATEDIFF(
    [Max Sales Date],
    TODAY(),
    MONTH
)

Then I made a simple IF() comparison:

Lost Customer = 
IF(
    [Duration] > 4,
    "Lost",
    BLANK()
)

That gave me a table that looks like this:

image.png

 

You can hide the intermediate measures, or combine them into one big complex measure if desired.

See this file.



Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

Hi @edhans  can It works as column not measure? 

Not as written, but why would you want to? In general, try to avoid calculated columns. There are times to use them, but it is rare. Getting data out of the source system, creating columns in Power Query, or DAX Measures are usually preferred to calculated columns. See these references:
Calculated Columns vs Measures in DAX
Calculated Columns and Measures in DAX
Storage differences between calculated columns and calculated tables
SQLBI Video on Measures vs Calculated Columns




Did I answer your question? Mark my post as a solution!
Did my answers help arrive at a solution? Give it a kudos by clicking the Thumbs Up!

DAX is for Analysis. Power Query is for Data Modeling


Proud to be a Super User!

MCSA: BI Reporting

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors