Forum Discussion
Date filter
What is the best practice to add From date and To Date filters on my report and default them to a week?
6 Replies
- MattAllingtonCommunity Champion
I don't think there is one best way. How about using the date timeline slicer on you calendar date table and set it to weeks.
https://powerbi.microsoft.com/en-us/blog/visual-awesomeness-unlocked-the-timeline-slicer/
- Greg_DecklerCommunity Champion
gjadal - Can you add a little detail to this, are you trying to default the selection to the current week?
- gjadalMicrosoft Employee
Basically I want a from date control and a To date control where the user can pick dates to filter the data.
By default I want the dates to be 1 week apart.
I tried using the time slicer but that doesnt have weeks as an option and its not very elegant..
- MattAllingtonCommunity Champion
I don't know of any way to set a "default" period apart. You could set a start date and a "number of weeks" slicer and set that to 1. Then the user could change it from 1 week to anything else. Just an idea.
Or you could create 2 calendar tables, one for the FROM and one for the TO date.
each table should have a single column that contains the week date you want, eg week commencing dates or week ending - what ever you want.
don't join them to anything
write 2 harvester measures to "harvest" what has been selected.
From Date=max(FromCal[Date])
To Date = max(ToCal[Date])
write the a measure that reacts to the slicers. Something like this.
total sales selected period =
CALCULATE (sum(Sales[qty]),
filter (Sales,
Sales[date] >= [From Date] &&
Sales[Date] <= [To Date]
)
)