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

Create a filter/Slicer for Last week, Last Month & Last Quarter

Hi I would like to create filter which allows me to select the last week of data or the last month or the last quarter. My Visual is laid as per the below image.

I do have a date table which has weeknumber,month number etc...

 

Table visualTable visual

1 ACCEPTED SOLUTION
v-eqin-msft
Community Support
Community Support

Hi @Anonymous ,

 

You could simply select the slicer type as "Relative Date":

Relative date.PNG

Or create a new table for slicer:

slicer type.PNG

Then try the following formula to create a measure:

Measure = 
var _week = IF(DATEDIFF(MAX('Table'[Week End]),TODAY(),WEEK)=1,1,0)
var _month= IF(DATEDIFF(MAX('Table'[Week End]),TODAY(),MONTH)=1,1,0)
var _quarter=IF(DATEDIFF(MAX('Table'[Week End]),TODAY(),QUARTER)=1,1,0)
return SWITCH(MAX('ForSlicer'[Type]),"Last Week", _week,"Last Month",_month,"Last Quarter",_quarter)

Last, apply the measure to filter pane, set as "=1":

last date.gif

 

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

View solution in original post

4 REPLIES 4
v-eqin-msft
Community Support
Community Support

Hi @Anonymous ,

 

You could simply select the slicer type as "Relative Date":

Relative date.PNG

Or create a new table for slicer:

slicer type.PNG

Then try the following formula to create a measure:

Measure = 
var _week = IF(DATEDIFF(MAX('Table'[Week End]),TODAY(),WEEK)=1,1,0)
var _month= IF(DATEDIFF(MAX('Table'[Week End]),TODAY(),MONTH)=1,1,0)
var _quarter=IF(DATEDIFF(MAX('Table'[Week End]),TODAY(),QUARTER)=1,1,0)
return SWITCH(MAX('ForSlicer'[Type]),"Last Week", _week,"Last Month",_month,"Last Quarter",_quarter)

Last, apply the measure to filter pane, set as "=1":

last date.gif

 

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

Anonymous
Not applicable

This is quite cool, first option is not doable for me as baseg in UK and week start/end isnt correct ISO standard, Mon-Sun. Your second option works but need Date on the visual ?

amitchandak
Super User
Super User

@Anonymous , as last week and last month are overlapping. You can not do that in date table.

You have to  create an independent table with these values and then using these values you have to create a measure, just like measure slicer

 

measure slicer
https://www.youtube.com/watch?v=b9352Vxuj-M
https://community.powerbi.com/t5/Desktop/Slicer-MTD-QTD-YTD-to-filter-dates-using-the-slicer/td-p/500115

 

Another example that can help

https://community.powerbi.com/t5/Desktop/Required-custom-date-Slicer-Last-7-days-last-15-days-last-30/m-p/1284966#M561629

 

Power BI Abstract Thesis: Need of an Independent Table in Power BI: https://youtu.be/lOEW-YUrAbE

What is the DAX if I am looking for LAST MONTH - not MTD. Example - it is Oct.2.2023 and I need last Month (Calendar) 9.1-9.30. I do not want weeks or days so Relative slicer does not meet my requirements. 

Thanks!

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.