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
MarcLykke
Frequent Visitor

How to count a later order of a specific product type and within a certain time frame

Hi everyone

I am trying to determine whether if a person's previous order is followed by another (specific product type of) order in the future.

 

In the example below I want to determine whether a previous order is followed by another order of the product type B. Futhermore, the following order of the product type B must be placed within 31 days from the previous order to be valued with a "Yes".

 

Can anyone help me how to write the DAX to create the following new column? ("Later order B +31 days")

Order IDPerson IDOrder dateProduct typeLater order B +31 days
1129/11 2021AYes
2105/12 2021BNo
3110/12 2021CNo
4106/03 2022BNo
1 ACCEPTED SOLUTION
Greg_Deckler
Community Champion
Community Champion

@MarcLykke Try something like:

 

Column =
  VAR __CurrentDate = [Order date]
  VAR __Customer = [Person ID]
  VAR __NextOrderDate = MINX(FILTER('Table',[Person ID] = __Customer && [Order date] > __CurrentDate),[Order date])
  VAR __NextProduct = MINX(FILTER('Table',[Person ID] = __Customer && [Order date] > __NextOrderDate),[Product type])
RETURN
  IF(__NextProduct = "B" && (__NextOrderDate - __CurrentDate) * 1. <= 31, "Yes", "No")

 

The basic pattern is taken from MTBF. 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/3395....
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...

View solution in original post

3 REPLIES 3
johnt75
Super User
Super User

Later order B + 31 Days =
var currentCustomer = 'Table'[Person ID]
var currentDate = 'Table'[Order date]
return IF( ISEMPTY( FILTER( ALL('Table'), 'Table'[Person ID] = currentCustomer && 
   'Table'[Order date] <= currentDate + 31 ) ), "No", "Yes" )
Greg_Deckler
Community Champion
Community Champion

@MarcLykke Try something like:

 

Column =
  VAR __CurrentDate = [Order date]
  VAR __Customer = [Person ID]
  VAR __NextOrderDate = MINX(FILTER('Table',[Person ID] = __Customer && [Order date] > __CurrentDate),[Order date])
  VAR __NextProduct = MINX(FILTER('Table',[Person ID] = __Customer && [Order date] > __NextOrderDate),[Product type])
RETURN
  IF(__NextProduct = "B" && (__NextOrderDate - __CurrentDate) * 1. <= 31, "Yes", "No")

 

The basic pattern is taken from MTBF. 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/3395....
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...

Thank you very much Greg!

I changed the variable for Next product to be similar to the variable for Next order date so they both need to have an order date larger than the Currentdate. But maybe there is a deeper meaning behind you using Order date > NextOrderDate in the variable for Next product? 🙂

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.

Top Solution Authors