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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
Jinyang00
New Member

Calculate daily new user count within relative period

This is raw data - daily sales data with Order date, Order ID. 

 

Order dateID 
12/25/2023Q
12/25/2023X
12/26/2023A
12/27/2023Y
12/28/2023Z
12/29/2023W
12/30/2023P
12/31/2023A
12/31/2023J
12/31/2023N
1/1/2024A
1/1/2024B
1/2/2024N
1/2/2024D
1/2/2024F
1/3/2024A
1/3/2024B
1/4/2024J
1/4/2024G
1/4/2024H
1/5/2024B
1/6/2024J
1/7/2024H
1/8/2024L
1/9/2024M
1/10/2024N

 

I want to calculate daily new user # - new user definition is 1) Purchased on that day and 2) No purchase in last week (from day -7 to day-1).  To do this, need to calculate "# of ID" in last week(from day -7 to day -1) by each date and ID then if this count is '0', then it will be new user.  

 

Order dateID Date -7Date -1# of order in last week (day -6 to day -1)New user
12/25/2023Q12/18/202312/24/2023n/an/a
12/25/2023X12/18/202312/24/2023n/an/a
12/26/2023A12/19/202312/25/2023n/an/a
12/27/2023Y12/20/202312/26/2023n/an/a
12/28/2023Z12/21/202312/27/2023n/an/a
12/29/2023W12/22/202312/28/2023n/an/a
12/30/2023P12/23/202312/29/2023n/an/a
12/31/2023A12/24/202312/30/2023n/an/a
12/31/2023J12/24/202312/30/2023n/an/a
12/31/2023N12/24/202312/30/2023n/an/a
1/1/2024A12/25/202312/31/202330
1/1/2024B12/25/202312/31/20230New user
1/2/2024N12/26/20231/1/20242 
1/2/2024D12/26/20231/1/20240New user
1/2/2024F12/26/20231/1/20240New user
1/3/2024A12/27/20231/2/20243 
1/3/2024B12/27/20231/2/20242 
1/4/2024J12/28/20231/3/20242 
1/4/2024G12/28/20231/3/20240New user
1/4/2024H12/28/20231/3/20240New user
1/5/2024B12/29/20231/4/20243 
1/6/2024J12/30/20231/5/20243 
1/7/2024H12/31/20231/6/20242 
1/8/2024L1/1/20241/7/20240New user
1/9/2024M1/2/20241/8/20240New user
1/10/2024N1/3/20241/9/20240New user

 

Final results needed is as daily new user count. 

 

DateNew user count
1/1/20241
1/2/20242
1/3/20240
1/4/20242
1/5/20240
1/6/20240
1/7/20240
1/8/20241
1/9/20241
1/10/20241

 

How can  I calculate this using Power BI?

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Jinyang00 ,

 

According to your description, here are my steps you can follow as a solution.

(1) My test data is the same as yours.

(2) We can create calculated columns.

Date -7 = [Order date]-7
Date -1 = [Order date]-1
# of order in last week (day -6 to day -1) = 
 var _a=CONVERT(COUNTROWS(FILTER('Table','Table'[ID]=EARLIER('Table'[ID]) && 'Table'[Order date]<=EARLIER('Table'[Date -1]) && 'Table'[Order date] >=EARLIER('Table'[Date -7]))),STRING)
 var _b=IF(_a=BLANK(),"0",_a)
 return IF([Order date]<DATE(2024,1,1),"n/a",_b)
New user = IF([# of order in last week (day -6 to day -1)]="0","new user")

(3) We can create a measure.

Count = IF(COUNT('Table'[New user])=BLANK(),0,COUNT('Table'[New user]))

(4) Then the result is as follows.

vtangjiemsft_0-1705027142555.png

 

Best Regards,

Neeko Tang

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

2 REPLIES 2
Dangar332
Super User
Super User

hi, @Jinyang00 

try below code for new column 

Column = 
var a = MINX( FILTER(newcustomer,[Order date]>=EARLIER(newcustomer[Order date])-7),[Order date])
var a1 = MIN(newcustomer[Order date])+7
var b = MAXX(FILTER(newcustomer,newcustomer[Order date]<=EARLIER(newcustomer[Order date])-1),[Order date])
var c = CALCULATETABLE(VALUES(newcustomer[ID ]),newcustomer[Order date]>=a,newcustomer[Order date]<=b,REMOVEFILTERS())
return
IF(newcustomer[Order date]<a1,BLANK(),IF(newcustomer[ID ] in c ,BLANK(),1))+0

 

Dangar332_1-1705057072811.png

 

 

Dangar332_0-1705056953764.png

 

download file click HERE 

 

 

 

Anonymous
Not applicable

Hi @Jinyang00 ,

 

According to your description, here are my steps you can follow as a solution.

(1) My test data is the same as yours.

(2) We can create calculated columns.

Date -7 = [Order date]-7
Date -1 = [Order date]-1
# of order in last week (day -6 to day -1) = 
 var _a=CONVERT(COUNTROWS(FILTER('Table','Table'[ID]=EARLIER('Table'[ID]) && 'Table'[Order date]<=EARLIER('Table'[Date -1]) && 'Table'[Order date] >=EARLIER('Table'[Date -7]))),STRING)
 var _b=IF(_a=BLANK(),"0",_a)
 return IF([Order date]<DATE(2024,1,1),"n/a",_b)
New user = IF([# of order in last week (day -6 to day -1)]="0","new user")

(3) We can create a measure.

Count = IF(COUNT('Table'[New user])=BLANK(),0,COUNT('Table'[New user]))

(4) Then the result is as follows.

vtangjiemsft_0-1705027142555.png

 

Best Regards,

Neeko Tang

If this post  helps, then please consider Accept it as the solution  to help the other members find it more quickly. 

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.