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

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Learn more

Reply
Anonymous
Not applicable

Continuous cumulative count based on discrete dates

Hi all,

 

I have a table with customer IDs, and the date of their first, second, third, and fourth car purchases. (Some customers might not have four purchases, for them the dates would be 2099, data shown below) 

 

What I need is, for each day, I would like to know how many customers have one car, how many customers have two cars etc. Basically I want to plot the distribution of customers based on how many cars they have against time, and this plot should cover all days from first purchase date until today. For example, first car is purchased on 12th Feb 2019

On this date %100 of my customers have one car. 1 day later on 13th Feb, still %100 of my customers have one car.

On 15th Feb 2019, same customer purchases a car again, so %100 of my customers have two cars. 

On 3rd October, 2019 another customer purchases a car, now I have two customers, one of them have one car and one of them have two cars, and I would like to plot their distribution.

 

Basically my X axis should be the dates, and on Y axis I would like to have percentage of customers who have one car, two cars and so on. Would appreciate the help so much! Thanks in advance

 

Customer_IDFirst_PurchaseSecond_PurchaseThird_PurchaseFourth_Purchase
712 Feb 201915 Feb 201922 May 201925 May 2019
53 Oct 20191 Jan 20991 Jan 20991 Jan 2099
328 Dec 201929 Mar 202031 Mar 20231 Jan 2099
916 Jan 202020 Nov 20211 Jan 20991 Jan 2099
830 Sep 20209 Aug 202118 Dec 20211 Jan 2099
46 Dec 202023 Sep 20211 Jan 20991 Jan 2099
111 Jan 202122 Sep 20211 Jan 20991 Jan 2099
614 Jan 202222 Dec 202222 Feb 20231 Jan 2099
227 Jun 202327 Jun 20231 Jan 20991 Jan 2099
2 ACCEPTED SOLUTIONS

Hi,

Please find attached the solution workbook.

Hope this helps.

Untitled.png


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

View solution in original post

Hi,

Go To Home > Transform Data.  click on The Categories query and double click on Source.  Make changes there and click on OK.  Click on Close and Apply.

Hope this helps.


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

View solution in original post

12 REPLIES 12
Ashish_Mathur
Super User
Super User

Hi,

Based on the Table that you have shared, show the expected result in a simple Table format.


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

Hi Ashish

Thanks for your response. Please see below

 

DateNumber of customers with 1 carsNumber of customers with 2 carsNumber of customers with 3 carsNumber of customers with 4 cars
11 Feb 20190000
12 Feb 20191000
13 Feb 20191000
14 Feb 20191000
15 Feb 20190100
.....0100
3 Oct 20191100
4 Oct 20191100
....    
28 Dec 20192100

 

 

Hi,

Please find attached the solution workbook.

Hope this helps.

Untitled.png


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

Hi Ashish,

 

Awesome, this works thank you so much!

You are welcome.


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

Hi Ashish,

 

I have a one final question I hope it is not too much. In my dataset there are customers who has more than 4 purchases, some customers have 10 purchases. So instead of clubbing the customers by 1-2-3-4 purchases, i would like to club them as 1purchase,2purchase,3 purchase, 4 and more than 4 purchases.

 

Is this something that can be accomodated as well? Basically subsequent purchases after 4 should still stay in the same final bucket (4 and 4+ purchases)

Hi,

Go To Home > Transform Data.  click on The Categories query and double click on Source.  Make changes there and click on OK.  Click on Close and Apply.

Hope this helps.


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

Great, did this as well and it works. I am also wondering in case there if there is a customer buying two cars on the same day, how would it reflect?

 

If the customer does not have any car and purchases his first and second cars on the same date, then ideally this customer should be counted as zero cars before the purchase, and 'two cars' on the next day

That is how it should work.  Test it yourself.


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

Hi Ashish, thank you so much for all your support, it is all working, however when I create a relationship with another table (it is a one on one relationship based on the customer ID), the formula is breaking, would you have any idea why? or would I need to share more information

I have no idea.


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

@Anonymous I would start by unpivoting the four columns after your Customer_ID column. Then you will need something like the following: 
Take a look at these two Quick Measures as I think you want something like them.

https://community.powerbi.com/t5/Quick-Measures-Gallery/Open-Tickets/m-p/409364
https://community.powerbi.com/t5/Quick-Measures-Gallery/Periodic-Billing/m-p/409365

 

Of course, yours will be a variation where you will need to find the "previous value" for the purchase prior to the next purchase:

See my article on Mean Time Between Failure (MTBF) which uses EARLIER: http://community.powerbi.com/t5/Community-Blog/Mean-Time-Between-Failure-MTBF-and-Power-BI/ba-p/339586.
The basic pattern is:
Column = 
  VAR __Current = [Value]
  VAR __PreviousDate = MAXX(FILTER('Table','Table'[Date] < EARLIER('Table'[Date])),[Date])

  VAR __Previous = MAXX(FILTER('Table',[Date]=__PreviousDate),[Value])
RETURN
  __Current - __Previous



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Fabric Data Days Carousel

Fabric Data Days

Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!

October Power BI Update Carousel

Power BI Monthly Update - October 2025

Check out the October 2025 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.