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
Anonymous
Not applicable

DAX to create a date filter

Hello,

 

Can anyone help me with creating a date filter to include all dates in the range of past 6 months and next 6 months relative to today's date..assuming date_dt is the date field

6 REPLIES 6
dax
Community Support
Community Support

Hi @Anonymous ,

You could refer to @amitchandak ' suggestions, or you also could try to +/-180 days like below

Measure = CALCULATE(SUM(t2[amount]), FILTER(t2, t2[date]<=DATE(YEAR(TODAY()), MONTH(TODAY()), DAY(TODAY())+180)&& t2[date]>=DATE(YEAR(TODAY()), MONTH(TODAY()), DAY(TODAY())-180)))

713.PNG

Best Regards,
Zoe Zhi

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

Anonymous
Not applicable

Thanks Zoe Zhi

amitchandak
Super User
Super User

@Anonymous ,

Measure =
var _min = date(year(today()),month(today())-6,day(today())) /// or date(year(today()),month(today())-6,1)
var _max = date(year(today()),month(today())+6,day(today())) /// eomonth(date(year(today()),month(today())+6,day(today())),0)
return
calculate([measure],filter(All(DATE), Date[Date] >=_min && Date[Date] <=_max))

Anonymous
Not applicable

Thanks Amit

nandukrishnavs
Super User
Super User

@Anonymous 

 

Try something like this 

 

Measure  = CALCULATE(SUM(MyTable[Sales]),FILTER(ALL(MyTable[date_dt]),MyTable[date_dt]>=TODAY()-180 || MyTable[date_dt]<= TODAY()+180))

 



Did I answer your question? Mark my post as a solution!
Appreciate with a kudos
🙂


Regards,
Nandu Krishna

Anonymous
Not applicable

Thanks Nandu

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.