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! Request now

Reply
RachC
Helper I
Helper I

Contain value in Slicer

Buddies ,I want to design a filter that could  choose 

  1. this week
  2. this month
  3. this year

I make a DAX function

      

thisDate = IF(WEEKNUM([_DATE]) = WEEKNUM(NOW()),"THIS WEEK",
IF(MONTH([_DATE]) = MONTH(NOW()),"THIS MONTH"),
IF(YEAR([_DATE] = YEAR(NOW()),"THIS YEAR")))

 

It work in my column.However, I can't choose "THIS MONTH" include "THIS WEEK".Therefore,I modified the code.

 

thisDate = IF(WEEKNUM([_DATE]) = WEEKNUM(NOW()),1,
IF(MONTH([_DATE]) = MONTH(NOW()),2),
IF(YEAR([_DATE] = YEAR(NOW()),3)))

I selected number of three that smaller one need to be selected.Is possible?

 

btw,If the way come true,the filter will show the 1 ,2 and 3.Can It be modified(i.e.:"this week")?

2 REPLIES 2
Anonymous
Not applicable

Hi @RachC,

 

You can use below formula to check the date range:

 

Measure:
CheckDate = 
var checkYear=YEAR(MAX('Table'[Date]))=YEAR(NOW())
var checkMonth=MONTH(MAX('Table'[Date]))=MONTH(NOW())
var checkWeek=WEEKNUM(MAX('Table'[Date]),1)=WEEKNUM(NOW(),1)
return
IF(checkYear,if(checkWeek,"This Week",if(checkMonth,"This Month","This Year")),"Different Year")

 

 

Capture.PNG

 

In addition, you can also take a look at following formula which check date based on slicer:

 

Measures:
Selected = if(HASONEVALUE('Table'[Date]),VALUES('Table'[Date]),BLANK())

CheckDate(Slicer) = 
var checkYear=YEAR([Selected])=YEAR(NOW())
var checkMonth=MONTH([Selected])=MONTH(NOW())
var checkWeek=WEEKNUM([Selected],1)=WEEKNUM(NOW(),1)
return
IF(checkYear,if(checkWeek,"This Week",if(checkMonth,"This Month","This Year")),"Different Year")

 

Capture2.PNG

 

Regards,

Xiaoxin Sheng

um..it can't resolve my problem.

I thought I explain accurately,the filter need latest 7 day,14 day.

If you set the label in column like this week or this latest14day that you can't contain the other inforamation unless you choose both.But it's not my goal.

I found the M code but I didn't implement with this blog.If it works well I will share in this post!

Helpful resources

Announcements
November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

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!

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