cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous
Not applicable

Required custom date Slicer Last 7 days,last 15 days,last 30 days

Hi Team,

I have 3 columns 
ID LastUpdateddate Values
1   2020-08-10          100
2   2020-07-12           200
3   2020-08-01            500
4   2020-08-05           700
5    2020-05-15          800
6    2020-07-30          100


I need a date slicer in that i required last7days,last15days,last30 option

once i select last7 days filter , table should display last 7days records only and so on for other option.

Date filter
last7days
last15days
last30days

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

Hi @Anonymous ,

 

If you want to create slicer like following screenshot, we can use the following ways to meet your requirement.

 

R1.jpg

 

1. Create a date table and a date slicer table. There is no relationship among tables.

 

Date = CALENDAR("2020/5/1","2020/8/31")

 

R2.jpg

 

2. Create three measure to calculate the last 7 days, last 15 days and last 30 days.

 

Last7days = 
var _select = SELECTEDVALUE('Date'[Date])
var _last7days = _select-7
var _last7values = CALCULATE(SUM('Table'[Values]),FILTER('Table','Table'[LastUpdateddate]<=_select&&'Table'[LastUpdateddate]>=_last7days))
return
IF(
    ISFILTERED('Date'[Date]),
    _last7values,
    SUM('Table'[Values]))

 

Last15Days = 
var _select = MIN('Date'[Date])
var _last15days = _select-15
var _last15values = CALCULATE(SUM('Table'[Values]),FILTER('Table','Table'[LastUpdateddate]<=_select&&'Table'[LastUpdateddate]>=_last15days))
return
IF(
    ISFILTERED('Date'[Date]),
    _last15values,
    SUM('Table'[Values]))

 

Last30Days = 
var _select = MIN('Date'[Date])
var _last30days = _select-30
var _last30values = CALCULATE(SUM('Table'[Values]),FILTER('Table','Table'[LastUpdateddate]<=_select&&'Table'[LastUpdateddate]>=_last30days))
return
IF(
    ISFILTERED('Date'[Date]),
    _last30values,
    SUM('Table'[Values]))

 

R3.jpg

 

3. At last we can create a measure to get the result.

 

Result measure = 
var _select = SELECTEDVALUE('Date filter'[slicer])
return
IF(
    ISFILTERED('Date filter'[slicer]),
    SWITCH(
        TRUE(),
        _select="last7days",[Last7days],
        _select="last15days",[Last15Days],
        _select="last30days",[Last30Days]
    ))

 

R4.jpg

 

R5.jpg

 

If it doesn’t meet your requirement, could you please show the exact expected result based on the table that you have shared?

 

Best regards,

 

Community Support Team _ zhenbw

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

 

BTW, pbix as attached.

View solution in original post

5 REPLIES 5
v-zhenbw-msft
Community Support
Community Support

Hi @Anonymous ,

 

If you want to create slicer like following screenshot, we can use the following ways to meet your requirement.

 

R1.jpg

 

1. Create a date table and a date slicer table. There is no relationship among tables.

 

Date = CALENDAR("2020/5/1","2020/8/31")

 

R2.jpg

 

2. Create three measure to calculate the last 7 days, last 15 days and last 30 days.

 

Last7days = 
var _select = SELECTEDVALUE('Date'[Date])
var _last7days = _select-7
var _last7values = CALCULATE(SUM('Table'[Values]),FILTER('Table','Table'[LastUpdateddate]<=_select&&'Table'[LastUpdateddate]>=_last7days))
return
IF(
    ISFILTERED('Date'[Date]),
    _last7values,
    SUM('Table'[Values]))

 

Last15Days = 
var _select = MIN('Date'[Date])
var _last15days = _select-15
var _last15values = CALCULATE(SUM('Table'[Values]),FILTER('Table','Table'[LastUpdateddate]<=_select&&'Table'[LastUpdateddate]>=_last15days))
return
IF(
    ISFILTERED('Date'[Date]),
    _last15values,
    SUM('Table'[Values]))

 

Last30Days = 
var _select = MIN('Date'[Date])
var _last30days = _select-30
var _last30values = CALCULATE(SUM('Table'[Values]),FILTER('Table','Table'[LastUpdateddate]<=_select&&'Table'[LastUpdateddate]>=_last30days))
return
IF(
    ISFILTERED('Date'[Date]),
    _last30values,
    SUM('Table'[Values]))

 

R3.jpg

 

3. At last we can create a measure to get the result.

 

Result measure = 
var _select = SELECTEDVALUE('Date filter'[slicer])
return
IF(
    ISFILTERED('Date filter'[slicer]),
    SWITCH(
        TRUE(),
        _select="last7days",[Last7days],
        _select="last15days",[Last15Days],
        _select="last30days",[Last30Days]
    ))

 

R4.jpg

 

R5.jpg

 

If it doesn’t meet your requirement, could you please show the exact expected result based on the table that you have shared?

 

Best regards,

 

Community Support Team _ zhenbw

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

 

BTW, pbix as attached.

View solution in original post

amitchandak
Super User IV
Super User IV

@Anonymous , I think the same issue as -

https://community.powerbi.com/t5/Desktop/required-custom-date-sllicer-Last-7-days-last-15-days-last-30/m-p/1284551#M561530

 

Else create slicer like this -

https://community.powerbi.com/t5/Desktop/Slicer-MTD-QTD-YTD-to-filter-dates-using-the-slicer/td-p/50...

 

And use rolling measure -


Rolling 7 days = CALCULATE(sum(Sal[Sales Amount]),DATESINPERIOD('Date'[Date],max(Sales[Sales Date]),-7,Day))


Rolling 14 days = CALCULATE(sum(Sal[Sales Amount]),DATESINPERIOD('Date'[Date],max(Sales[Sales Date]),-14,Day))

 

In case you need to display all dates

https://www.youtube.com/watch?v=duMSovyosXE



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!

parry2k
Super User III
Super User III

@Anonymous   use relative date filtering

 

I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos whoever helped to solve your problem. It is a token of appreciation!

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.






Did I answer your question? Mark my post as a solution.

Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.





Anonymous
Not applicable

@parry2k But user wants custom date filter, they dont need relative filter,

@Anonymous check this post and tweak it as per your need.

 

I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos whoever helped to solve your problem. It is a token of appreciation!

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.






Did I answer your question? Mark my post as a solution.

Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.





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

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

July 2021 Update 768x460.png

Check it out!

Click here to read more about the July 2021 Updates

Power Query PA Forum 768x460.png

Check it out!

Did you know that you can visit the Power Query Forum in Power BI and now Power Apps

Top Solution Authors
Top Kudoed Authors