Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

Reply
joshrumbawa
Frequent Visitor

Date and Time Relative Filter

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.

joshrumbawa_0-1708149381158.png

 

6 REPLIES 6
v-tangjie-msft
Community Support
Community Support

Hi @joshrumbawa ,

 

According to your description, here are my steps you can follow as a solution.

(1) This is my test data. 

vtangjiemsft_0-1708326694175.png

(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.

vtangjiemsft_1-1708326861265.pngvtangjiemsft_2-1708326889072.png

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!

joshrumbawa_0-1708495232425.png

 

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.

joshrumbawa_0-1708437262263.png

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!

Greg_Deckler
Super User
Super User

@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...


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Fabcon_Europe_Social_Bogo

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

Check out the June 2024 Power BI update to learn about new features.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.