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.
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?
@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:
Hi,
You may download my PBI file from here.
Hope this helps.
There is a tried and tested pattern for this. I have used it and it works. https://www.daxpatterns.com/new-and-returning-customers/
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
109 | |
98 | |
80 | |
64 | |
57 |
User | Count |
---|---|
145 | |
111 | |
92 | |
84 | |
66 |