cancel
Showing results for
Did you mean:
Frequent Visitor

## Propagation of customer level measure to the order level

I have an order table and based on the creation date of the order I am trying to calculate the count of new customer/returning customers and revenue created by both segment. Is it a bit more complicated because I want to have it dynamic based on the period that a user choses. (Attached is the power bi notebook with my failed attempts to calculate this :))

Here is the data example I use:

 customer order created_at_date amount A A1 01.01.20 60 A A2 10.01.20 10 A A3 30.01.20 200 B B1 23.09.19 10 B B2 01.01.20 20 B B3 10.01.20 35 C C1 23.09.19 10 C C2 30.01.20 15

Desired result & explanation:
Let's say I want to see number of new/returning customers only for 01.01.2020. Based on the example above, customer A did its first order (A1) on 01.01.2020, hence customer A is a new customer for the given period (01.01.2020). Customer B did his first order (B1) on 23.09.19 and the second order (B2) was done on 01.01.202, hence, customer B is a returning customer for the given period.
The revnue generated by new customer and returning customer for the period of 01.01.2020 is:
new customer: 60 (A1) and returning customer: 10 (B2).

If I do the same calculations for the whole month of Janury for 2020, it will be like this:

 returning customer new customer count 2 (B & C) 1 (A) revenue 70 (B2+B3 +C2) 270 (A1+A2+A3)

My logic to calculate this was the following:
As a have a date slicer, I count number of orders before the latest date of the slicer and number of orders that were placed between the dates specified in the slicer. If those two numbers are equal, then it is a new customer.

Here is the calculation for the new customer:

`IsNewCustomer = VAR EndDate = lastdate('Book1'[created_at_date])VAR StartDate = firstdate('Book1'[created_at_date])VAR OrdersTillNow = CALCULATE ( DISTINCTCOUNT ( 'Book1'[order]),'Book1'[created_at_date]<=EndDate)VAR OrdersInPeriod = CALCULATE ( DISTINCTCOUNT ( 'Book1'[order]),'Book1'[created_at_date]<=EndDate, 'Book1'[created_at_date]>=StartDate)Return CALCULATE (OrdersTillNow = OrdersInPeriod)`

And then I tried to apply this to count new customers:

`Count New Customers = CALCULATE(DISTINCTCOUNT(Book1[customer]), filter(Book1, [IsNewCustomer]))`

And as you might already see, it doesn't work because the isNewCustomer is calculated on the customer level and not order level.

Question:
How could I achieve the desired result that I provided in the example?

3 REPLIES 3
Frequent Visitor

@Ashish_Mathur thank you for the notebook and the solution! Indeed, it does wotk for the small dataset.

However, if I have a big dataset and I want to display the number of new users over weeks/days, this solution doesn"t scale.

This is what I get from power bi desktop:

Super User III

Hi,

Hope this helps.

Regards,
Ashish Mathur
http://www.ashishmathur.com

There is a tried and tested pattern for this. I have used it and it works. https://www.daxpatterns.com/new-and-returning-customers/

* Matt is a Microsoft MVP (Power BI) and author of the Power BI Book Supercharge Power BI.

Announcements