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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
StefanM
Helper II
Helper II

Help! Relative Time Filter - Between Hours

Hi guys, I have a table with a column of Date-Time.

 

I need to use that column to filter charts between recent hours. For example: Past 5 hours, 5-24 hours, 24-72 hours, etc
I can't see any way to filter between hours, only "include everything from X hours ago"

 

This is what I've been able to create: 

StefanM_0-1612552793702.png


Using variations of:

StefanM_1-1612552804406.png

I've attached a PBX file to show it all in action: https://drive.google.com/file/d/1vsF-tN9O1FYRInWWDqCxPC3dNt5Yv3eL/view 

Anyone have any ideas how to do this?

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi  @StefanM  ,

Here are the steps you can follow:

1. Create calculated column.

Hour =
DATEDIFF(MAX('Table'[date]),NOW(),HOUR)
Hour_Column =
var _1=DATEDIFF('Table'[date],NOW(),HOUR)
return
SWITCH(
    TRUE(),
    _1>0&&_1<=5,"0-5",
    _1>5&&_1<=24,"5-24",
    "24-72")

2. Create measure

count of resopnse =
CALCULATE(COUNT('Table'[Legend]),FILTER('Table','Table'[Legend]=MAX('Table'[Legend])))

3. Place Hour_Column in Axis, Legend in Legend, and count of resopnse in Values

v-yangliu-msft_0-1612831091685.png

4. Result.

v-yangliu-msft_1-1612831091689.jpeg

 

You can downloaded PBIX file from here.

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi  @StefanM  ,

Here are the steps you can follow:

1. Create calculated column.

Hour =
DATEDIFF(MAX('Table'[date]),NOW(),HOUR)
Hour_Column =
var _1=DATEDIFF('Table'[date],NOW(),HOUR)
return
SWITCH(
    TRUE(),
    _1>0&&_1<=5,"0-5",
    _1>5&&_1<=24,"5-24",
    "24-72")

2. Create measure

count of resopnse =
CALCULATE(COUNT('Table'[Legend]),FILTER('Table','Table'[Legend]=MAX('Table'[Legend])))

3. Place Hour_Column in Axis, Legend in Legend, and count of resopnse in Values

v-yangliu-msft_0-1612831091685.png

4. Result.

v-yangliu-msft_1-1612831091689.jpeg

 

You can downloaded PBIX file from here.

 

Best Regards,

Liu Yang

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

lbendlin
Super User
Super User

You can add a calculated column

 

Interval = SWITCH(TRUE(),now()-'Table'[regDate]<5/24,"Last 5 hrs",now()-'Table'[regDate]<1,"5-24 hrs Ago",now()-'Table'[regDate]<3,"24-72 hrs Ago","72+ hrs Ago")

 

BUT! There are lots of buts here. This would require you to have a Direct Query data connection or a very frequent dataset refresh. It also works against local time which comes with its own big bag of hurt.

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.