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

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
ejones_2525
Frequent Visitor

Last 24 months dax query

Hi everyone, 

I'm trying to calculate no of orders with first order date within the last 24 months. I have a model that looks like this.

ejones_2525_0-1612189997884.png


I'm trying to achieve this. 

ejones_2525_1-1612190042949.png


Normally, the formula below works for me. It seems due to the modelling and some filter context that I have not been able to figure out, it is not grouping the items properly.

repeat orders last 24 months =
VAR maxfirstorderdate = MAX('repeat orders'[First Order Date])
RETURN
CALCULATE(
sum(order),
DATESBETWEEN('repeat orders'[First Order Date], EOMONTH(maxfirstorderdate, -24)+1, maxfirstorderdate
))

Looking forward to suggestions!
thanks
2 REPLIES 2
Greg_Deckler
Community Champion
Community Champion

@ejones_2525 - I would attach this by using FILTER to get a virtual table in a VAR and then use MINX to grab the first date. 

 

You may find this helpful - https://community.powerbi.com/t5/Community-Blog/To-bleep-With-Time-Intelligence/ba-p/1260000

Also, see if my Time Intelligence the Hard Way provides a different way of accomplishing what you are going for.

https://community.powerbi.com/t5/Quick-Measures-Gallery/Time-Intelligence-quot-The-Hard-Way-quot-TIT...



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...

Hi @Greg_Deckler  

I tried your documentation in the links you sent, however it didn't work for me unfortunately

thanks again for the reply

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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