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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
Anonymous
Not applicable

Time Comparison in Filter expression not working

I have a simple table that looks like this...

TimeID NumberBaseline
12:00 AM001123
1:00 AM001256
11:00 PM001269
12:00 AM002796
1:00 AM002456

 

The time is for 24 hours. I need to find the sum of Baseline for each ID number only between the 3 hr time window of 1:00PM to 3:00 PM.

 

I used this measure: 

CALCULATE(SUM(Table[Baseline]),Table[Time]>=TIMEVALUE("1:00 PM")&&Table[Time]<=TIMEVALUE("3:00 PM"))
 
However, the filter is not working. It shows the sum of baseline for each ID for all 24 hours, not for the 3 hour window. Not sure what is wrong here. 
 
 
1 ACCEPTED SOLUTION
jdbuchanan71
Super User
Super User

I meant there are no rows between 1:00 PM and 3:00 PM in the sample data you provided in your original post.
Is your time column set to time data type in your model?  The measure works as expected on the sample you provided.

jdbuchanan71_0-1671120018555.png

 

View solution in original post

7 REPLIES 7
jdbuchanan71
Super User
Super User

Glad to hear it's working for you now!  Have a good day.

jdbuchanan71
Super User
Super User

I meant there are no rows between 1:00 PM and 3:00 PM in the sample data you provided in your original post.
Is your time column set to time data type in your model?  The measure works as expected on the sample you provided.

jdbuchanan71_0-1671120018555.png

 

Anonymous
Not applicable

Thank you so much for the suggestion. That's where I went wrong. I built this table by summarizing another table. I changed the time data type for this one but forgot to change the type in the original table. Now that I fixed it, it's working great. Thank you so much for all your help @jdbuchanan71 

jdbuchanan71
Super User
Super User

That is because, in your dataset, there are no rows with a time between 1:00 PM and 3:00 PM

Anonymous
Not applicable

There is data between that time frame. Just to check, I calculated the sum without the time filter expression. And then put time as a filter. Chose between 1 to 3 pm. It shows the right result.

But whenever I put the time filter expression back into the measure, doesn't matter whatever time duration it is. It either shows empty or shows the total sum of 24 hours, not according to the time stated in the filter expression.

 

jdbuchanan71
Super User
Super User

@Anonymous 

Try it like this.

Time Amount =
CALCULATE (
    SUM ( 'Table'[Baseline] ),
    'Table'[Time] >= TIME ( 13, 0, 0 ) && 
    'Table'[Time] <= TIME ( 15, 0, 0 )
)
Anonymous
Not applicable

@jdbuchanan71 

Thank you for the answer. However, it comes out empty.

Helpful resources

Announcements
Europe Fabric Conference

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.

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

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

MayPowerBICarousel1

Power BI Monthly Update - May 2024

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