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
giorgiokatr
Helper V
Helper V

new customers in a selected period

customerpurchase
a1/1/2016
b1/1/2016
c1/2/2016
a1/2/2016
d1/3/2016
c1/3/2016
e1/3/2016

i would like to calculate the new customers.New customers are those who made a purchase and never purchaced again in the last 10 days

for example if i select 01/03/2016 new customers should be 3 and not 2 because customer c is considered as new (he purchaced at 01/03/2016 and before 19/02/2016   *10 days*)

1 ACCEPTED SOLUTION

@giorgiokatr

 

Modify the "Last Purchase" Calculated Column.

Change highlighted in red below

 

Last_Purchase =
CALCULATE (
    LASTDATE ( TableName2[purchase] ),
    FILTER (
        ALLEXCEPT ( TableName2, TableName2[customer], TableName2[product] ),
        TableName2[purchase] < EARLIER ( TableName2[purchase] )
    )
)

Regards
Zubair

Please try my custom visuals

View solution in original post

8 REPLIES 8

There are many approaches to this scenario.

 

One option is to adapt the code shown here: https://www.sqlbi.com/articles/computing-new-customers-in-dax/ to your specific scenario. Basically, you will need to change the limits of the filter, so to take into account the 10 days. The code will not be super-fast, because of the dynamic boundaries.

 

Another option, much simpler, is to check - for each event - whether a similar one (same customer) happened earlier than 10 days before. This results in a simple flag in your table, that you can later use in a measure to filter sales to new customers.

 


Have fun with DAX!

Alberto Ferrari
http://www.sqlbi.com

Alberto Ferrari - SQLBI

Hi @giorgiokatr

 

Try this. Add 2 calculated Columns as follows

 

Last_Purchase =
CALCULATE (
    LASTDATE ( TableName[purchase] ),
    FILTER (
        ALLEXCEPT ( TableName, TableName[customer] ),
        TableName[purchase] < EARLIER ( TableName[purchase] )
    )
)

 

DaysDifference =
DATEDIFF ( TableName[Last_Purchase], TableName[purchase], DAY )


Now use this MEASURE to Count New Customers at any specific date

New Customers =
CALCULATE (
    COUNTROWS ( TableName ),
    FILTER (
        TableName,
        [DaysDifference] > 10
            || ISBLANK ( TableName[Last_Purchase] )
    )
)

Regards
Zubair

Please try my custom visuals

thanks @Zubair_Muhammad @AlbertoFerrari and @Anonymous

 

@Zubair_Muhammad will this work if i have another column with products like this

customerproductpurchase
aradio1/1/2016
bradio1/1/2016
cradio1/2/2016
aradio1/2/2016
dtv1/3/2016
ctv1/3/2016
etv1/3/2016
   

if i want to calculate the same but for tv will it work?

Hi @giorgiokatr,

 

Does Zubair_Muhammad's solution meet your requirement? If yes, would you please accept the helpful reply as an answer so that others having similar concern can find the solution more easily? If not, then, what the correct result of "New customer" should be when taking [Product] into account? Please provide more description.

 

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.

If you rely on a calculated column, it will not work, as a calc col is computed statically. If you opt for a measure, then it will be completely dynamic and adapt to any selection, albeit a bit slower.

You can also refer to daxpatterns.com, where there is a whole section dedicated to new and returning customers (it is one of my favourite calculations, along with events in progress :))

 


Have fun with DAX!

Alberto Ferrari
http://www.sqlbi.com

Alberto Ferrari - SQLBI

How about show attributes of the new clients like: by vendors or products, How I can aproach that?

 

 

@giorgiokatr

 

Modify the "Last Purchase" Calculated Column.

Change highlighted in red below

 

Last_Purchase =
CALCULATE (
    LASTDATE ( TableName2[purchase] ),
    FILTER (
        ALLEXCEPT ( TableName2, TableName2[customer], TableName2[product] ),
        TableName2[purchase] < EARLIER ( TableName2[purchase] )
    )
)

Regards
Zubair

Please try my custom visuals
Anonymous
Not applicable

hi @giorgiokatr,

 

This blog will help you in setting this up the right way. http://www.daxpatterns.com/new-and-returning-customers/

 

Good luck!

 

 

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.