March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now
Hello PBI Experts, need your help with regards to Date and Time Filter. I have this requirement to create a slicer (Last 5 minutes, Last 15 minutes, Last Hour, Today, Yesterday, Last Month, Last Year, etc.) based on the Date/Time Closed from Current Day/Time.
I have 3 fact tables that needs to be filter, They all have Date/Time column. I can achieve the Today, Yesterday, Weeks, Months, and Year using Date Dimension table. However, I have no idea how to integrate this with Time (Last 6 hours, Last 5 minutes, etc.)
Is someone here have the same scenario, or how do you work on this? Any inputs is highly appreciated. Thank you!
They require me to make a filter something like this.
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 @v-tangjie-msft , 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!
Hi @v-tangjie-msft , 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.
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
Hi @v-tangjie-msft , 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!
@joshrumbawa So I think this generally falls into the camp of a Complex Selector. Your measure would look at the value in the slicer and then filter the rows according to the criteria. You may not use it as a filter in the Filters pane in your case but rather within the measure calculate the result you need. https://community.fabric.microsoft.com/t5/Quick-Measures-Gallery/The-Complex-Selector/m-p/1116633#M5...
This may also help as it shows how to use a disconnected table like your slicer in a single measure that does all the heavy lifting. Disconnected Table Trick as this article demonstrates: https://community.powerbi.com/t5/Community-Blog/Solving-Attendance-with-the-Disconnected-Table-Trick...
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.
Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.
User | Count |
---|---|
123 | |
85 | |
85 | |
70 | |
51 |
User | Count |
---|---|
205 | |
153 | |
97 | |
79 | |
69 |