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

Vote for your favorite vizzies from the Power BI Dataviz World Championship submissions. Vote now!

Reply
unclejemima
Post Patron
Post Patron

New customers from sales/transaction data

I'm trying to generate a report for 'new' customers in a month.

 

I found a good tutorial online...but I'm having trouble making it work.

 

The code they suggest looks like this...

 

 

New customers = 

VAR currentCustomers = VALUES('Sales table'[customer])
VAR currentDate = MIN('Sales table'[date])

VAR pastCustomers = CALCULATETABLE(VALUES('Sales table'[customer]), 
    ALL('Sales table'[date].[Month],'Sales table'[date].[MonthNo],'Sales table'[date].[Year])
    , 'Sales table'[date]<currentDate)

VAR newCustomers = EXCEPT(currentCustomers,pastCustomers)

RETURN COUNTROWS(newCustomers)

 

 

 

I'm doing this as a 'new measure'.

 

First issue I have is the with the VAR.  As I input this and it only has option for VAR.P, VAR.S  NOT for just VAR.  Is VAR a valid statement to call?

 

Secondly, when I get down to ALL('Sales table'[date].[Month] it is ok with Sales table[date] but as soon as I type .[Month] it will show red as an error.  

 

The sample table is VERY simple...looks like this...

New-and-Repeat-Customers-source-data.png

 

Here is a link to the full tutorial I was working from...

https://finance-bi.com/blog/power-bi-new-and-repeat-customers/

 

1 ACCEPTED SOLUTION
v-yalanwu-msft
Community Support
Community Support

Hi, @unclejemima ,

Try the measure.

New customers = 
VAR currentCustomers =SUMMARIZE(FILTER(ALL('Table'),EOMONTH([date],0)=EOMONTH(MAX('Table'[date]),0)),[customer])

VAR pastCustomers = SUMMARIZE(FILTER(ALL('Table'),EOMONTH([date],0)<EOMONTH(MAX('Table'[date]),0)),[customer])

VAR newCustomers = EXCEPT(currentCustomers,pastCustomers)

RETURN COUNTROWS(newCustomers)

The final show:

vyalanwumsft_0-1653358565266.png

If you want to get sum of new custom.

New customers  sales = 

VAR currentCustomers =SUMMARIZE(FILTER(ALL('Table'),EOMONTH([date],0)=EOMONTH(MAX('Table'[date]),0)),[customer])

VAR pastCustomers = SUMMARIZE(FILTER(ALL('Table'),EOMONTH([date],0)<EOMONTH(MAX('Table'[date]),0)),[customer])

VAR newCustomers = EXCEPT(currentCustomers,pastCustomers)

RETURN SUMX(newCustomers,CALCULATE(SUM([Sales])))


Best Regards,
Community Support Team _ Yalan Wu
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

3 REPLIES 3
v-yalanwu-msft
Community Support
Community Support

Hi, @unclejemima ,

Try the measure.

New customers = 
VAR currentCustomers =SUMMARIZE(FILTER(ALL('Table'),EOMONTH([date],0)=EOMONTH(MAX('Table'[date]),0)),[customer])

VAR pastCustomers = SUMMARIZE(FILTER(ALL('Table'),EOMONTH([date],0)<EOMONTH(MAX('Table'[date]),0)),[customer])

VAR newCustomers = EXCEPT(currentCustomers,pastCustomers)

RETURN COUNTROWS(newCustomers)

The final show:

vyalanwumsft_0-1653358565266.png

If you want to get sum of new custom.

New customers  sales = 

VAR currentCustomers =SUMMARIZE(FILTER(ALL('Table'),EOMONTH([date],0)=EOMONTH(MAX('Table'[date]),0)),[customer])

VAR pastCustomers = SUMMARIZE(FILTER(ALL('Table'),EOMONTH([date],0)<EOMONTH(MAX('Table'[date]),0)),[customer])

VAR newCustomers = EXCEPT(currentCustomers,pastCustomers)

RETURN SUMX(newCustomers,CALCULATE(SUM([Sales])))


Best Regards,
Community Support Team _ Yalan Wu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

AlexisOlson
Super User
Super User

VAR is not a function like VAR.P that calculates variation. It's a bit of code that tells DAX that you're defining a new variable. More detail here and here.

 

The .[month] and .[year] suffixes are related to automatic time intelligence and not really a good idea to use, in my personal opinion. It's generally better to have a proper date table.

 

I'd recommend checking out these resources related to customer retention:

https://www.daxpatterns.com/new-and-returning-customers

https://radacad.com/customer-retention-in-power-bi-dax-measures

Ashish_Mathur
Super User
Super User

Hi,

You may download my PBI file from here.

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

Vote for your favorite vizzies from the Power BI World Championship submissions!

Sticker Challenge 2026 Carousel

Join our Community Sticker Challenge 2026

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

January Power BI Update Carousel

Power BI Monthly Update - January 2026

Check out the January 2026 Power BI update to learn about new features.

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.