cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Gerald-BI
Helper I
Helper I

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
Eyelyn9
Community Support
Community Support

Hi @Gerald-BI ,

 

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

2 REPLIES 2
Eyelyn9
Community Support
Community Support

Hi @Gerald-BI ,

 

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

amitchandak
Super User IV
Super User IV

@Gerald-BI , 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/50...

 

Another example that can help

https://community.powerbi.com/t5/Desktop/Required-custom-date-Slicer-Last-7-days-last-15-days-last-3...

 

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



Did I answer your question? Mark my post as a solution! Appreciate your Kudos!!
Dashboard of My Blogs !! YouTube Channel !! Connect on Linkedin

Proud to be a Super User!

Helpful resources

Announcements
PBI User Groups

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Get Ready for Power BI Dev Camp

Power BI Dev Camp - June 24th

Mark your calendars and join us for our next Power BI Dev Camp!

Top Solution Authors
Top Kudoed Authors