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

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.

Reply
markus_zhang
Advocate III
Advocate III

Counting rebills only when they occur after 24 hours of previous purchase

Hi experts,

I'd like to count rebills only when they occur after 24 hours of previous purchase.

I have data of this format:

 

DateTime | Month | Transaction ID |  Item Code | Cash Amount | Sales Amount | Customer ID

 

[Month] is simply a calculated column: Month([DateTime])

 

I also have a Pivot Table with [Item Code] and [Month] on the row as I would like to check rebill rate of each merchandise for each month. I'm OK with the small flaw such that a purchase occurs at the first day of a month may be classified as a rebill while the last purchase occurred less than 24 hours ago.

 

My thought:

Since I want to ignore any [Transaction ID] made by the same [Customer ID] within 24 hours of this row (Using COUNTX() to add a row context), something similar to the following should work, in pseudo code:

 

Measure :=CALCULATE(COUNTX(Sales, Sales[Customer ID]), 
                       FILTER(Sales, Sales[DateTime] > Sales[DateTime] of this row plus 24 hours))

However because I cannot use EARLIER() to fetch Sales[DateTime] of this row, I'm kind of loss here. Would appreciate any help, and especially if you can share a general way to reference the current row in a measure.

5 REPLIES 5
Ashish_Mathur
Super User
Super User

Hi,

 

Share the link from where i can download your PBI file.


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

Hi I'm using Excel 365 and here is the link, thank you!

 

https://file.io/W9PTbm

Hi,

 

Write this calculated column formula in Table1

 

=if(ISBLANK(CALCULATE(max(Table1[Time]),FILTER(Table1,Table1[Customer ID]=EARLIER(Table1[Customer ID])&&Table1[Time]<EARLIER(Table1[Time])))),BLANK(),[Time]-CALCULATE(max(Table1[Time]),FILTER(Table1,Table1[Customer ID]=EARLIER(Table1[Customer ID])&&Table1[Time]<EARLIER(Table1[Time]))))

 

This column will give you "Time elapsed since previous purchase".  Now you should be able to write a measure with the condition that the time stamp in this colum should be <=TIME(24,0,0)

 

Hope this helps.


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

Thanks! Just curious, is there a way to do this in a measure without ADDCOLUMN()?

Hi,

 

I am not using the ADDCOLUMN() function.  I am using a calculated column formula.


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

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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