Forum Discussion
How can I filter data from datetime to datetime?
pxg08680 how can I do that?
- pxg086808 years agoResolver III
Even tought you get time field from all date time fields, how can you filter the data..?
The above datetime has some time values. Does your data contain the same for previous day also.
- stretcharm8 years agoMemorable Member
There is no way to do a datetime slicer and a range of date time is even worse.
I've played with a few options, but not got any to work particularly well.
There is a custom visualisation that does a time brush filter which would be good but it also doesn't use time.
The best I've got is using What If Parameters, using decimal parameters as a Datetime is stored as a decimal value with whole numbers being days and the decimals for the time.
There is no what if for date time so you have to use decimal
You can then edit the definition from
FromDateTime = GENERATESERIES(1, 20, 0.1)
To somethat that has range related to your data.
FromDateTime = GENERATESERIES(INT(MIN(Data[StartDateTime])), INT(MAX(Data[EndDateTime]))+1, 0.01)
You can also set the default dymanically
ToDateTime Value = SELECTEDVALUE(ToDateTime[ToDateTime], INT(TODAY())-1)
Create a new Computed Column to show the date time version
SelectedToDateTime = [ToDateTime Value]
Change this in modelling to a datetime with your preferred format. You can put this next to the slicer which is still show just a decimal value.
Sliding the slicer will update the value, but you've got to do a bit of trial and error to get the value you need.
Do the same for the ToDateTime
Now in the data set add a new Measure to check if the records are in the range specified by the slicers
IsInRange = if(min(Data[StartDateTime])>=FromDateTime[FromDateTime Value] && Max(Data[EndDateTime])<=ToDateTime[ToDateTime Value],1,0)
Finally add a filter to your visualisations or the page to only include values where IsInRange is 1
Its tricky to get the granualrity right for the time and slicers dont work well with large date ranges.
I've added my Solution to the How to Gallery
http://community.powerbi.com/t5/Data-Stories-Gallery/How-To-DataTime-Range-Slicer/m-p/306357#M1255
Hope this helps
Phil