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.
Hi Anonymous , I appreciate your response and that might be the solution.
Currently, I have a calculated column that connected to my Dim Date to filter those Dates Period then I will use the Selection column in the slicer.
I love your idea. However, I have multiple fact tables that needs to filter with one slicer from (This year, This month, etc. up to Last 5 mins). Do you know how do I do this? To be honest I got stuck on this issues and I'm having problems to find a solution. Appreciate your response.
- Anonymous2 years agoNot applicable
Hi joshrumbawa ,
I'm sorry I can't understand your needs, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. Thank you.
Best Regards,
Neeko Tang
- joshrumbawa2 years agoFrequent Visitor
Hi Anonymous , the method works. However, it's hard to maintain. I have this dashboard with a multiple fact tables and I need to apply the flag for all charts and also I have charts that uses measure and that will not work for this case.
The solution might be in a datamodel, I need to find another solution that will work for Date and Time. Thank you for the help!