Forum Discussion
Date and Time Relative Filter
Hi joshrumbawa ,
According to your description, here are my steps you can follow as a solution.
(1) This is my test data.
(2) We can create a slicer table.
Slicer = DATATABLE (
"Slicer", STRING,
{
{ "Last 5 minutes" },
{ "Last 6 hours" },
{ "Last 2 days" },
{ "Last Month" },
{ "Last Year" }
}
)
(3) We can create a measure.
Flag =
SWITCH(TRUE(),
ISFILTERED('Slicer'[Slicer])=FALSE(),1,
SELECTEDVALUE('Slicer'[Slicer])="Last 5 minutes" && MAX('FactTable1'[Date])<=NOW() && MAX('FactTable1'[Date])>=NOW()-TIME(0,5,0),1,
SELECTEDVALUE('Slicer'[Slicer])="Last 6 hours" && MAX('FactTable1'[Date])<=NOW() && MAX('FactTable1'[Date])>=NOW()-TIME(6,0,0),1,
SELECTEDVALUE('Slicer'[Slicer])="Last 2 days" && MAX('FactTable1'[Date])<=NOW() && MAX('FactTable1'[Date])>=TODAY()-1,1,
SELECTEDVALUE('Slicer'[Slicer])="Last Month" && MAX('FactTable1'[Date])<=NOW() && MAX('FactTable1'[Date])>=EDATE(TODAY(),-1),1,
SELECTEDVALUE('Slicer'[Slicer])="Last Year" && MAX('FactTable1'[Date])<=NOW() && MAX('FactTable1'[Date])>=DATE(YEAR(TODAY())-1,MONTH(TODAY()),DAY(TODAY())),1,0)
(4) Place [Flag=1] on the visual object screening and then the result is as follows.
Best Regards,
Neeko Tang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hello Anonymous , me again. I tried to test your concept, and it's working fine for dates Last 2 days, This Month, This Year. However, when I tried to filter Last 6 hours and Last 5 minutes I'm not getting any good result. It seems the condition is not met for the calculation of date time though the values of that measure seems right. Any thoughts? Thank you!