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

The FabCon + SQLCon recap series starts April 14th at 8am Pacific. If you’re tracking where AI is going inside Fabric, this first session is a can't miss. Register now

Reply
valentinaliac
Frequent Visitor

HELP! FILTER FIST AND LAST TIME HOURS PER DAY

Hi guys!

 

I have data from an Industrial Oven operation, that works in the following way: Every 30 minutes the operator has to record the entry of a tray. During that time, he rotates the trays up and down. When the tray reaches the bottom, he has to record the output mass. The thing is that not all the trays finish at the same time, maybe the material remains wet so it takes more time. I was asked to calculate per day how many hours did the oven worked. So I'm trying to filter by day, the first hour recorded and the last one and then substract them. But I'm struggling with that 😞

 

Someone knows how I can have this value?

 

Thank youuu!

 

DATETRAYFRUITENTRY OPERATORENTRY HOURENTRY MASS (KG)OUTPUT OPERATOROUTPUT DATEOUTPUT HOUROUTPUT MASS (KG)
28/03/20223Uchuva NaturalCarrillo, Pedro19:50:00150

Rodríguez, Marcos

29/03/20221:00:0033.4
28/03/20226Uchuva NaturalCarrillo, Pedro20:20:00150

Rodríguez, Marcos

29/03/20221:30:0032
28/03/20224Uchuva NaturalCarrillo, Pedro20:50:00150

Rodríguez, Marcos

29/03/20222:30:0032.2
28/03/20222Uchuva NaturalCarrillo, Pedro21:50:00150

Rodríguez, Marcos

29/03/20223:30:0034.3
28/03/20225Uchuva NaturalRodríguez, Marcos22:20:00150

Rodríguez, Marcos

29/03/20224:00:0034.4
28/03/202210Uchuva NaturalRodríguez, Marcos22:50:00150

Rodríguez, Marcos

29/03/20224:30:0033.8
28/03/20228Uchuva NaturalRodríguez, Marcos23:20:00150

Rodríguez, Marcos

29/03/20225:00:0034.2
28/03/202211Uchuva NaturalRodríguez, Marcos23:50:0041

Gutierrez, Jhon Jairo

29/03/20225:30:007.6
29/03/20221Uchuva NaturalRodríguez, Marcos0:20:00150

Rodríguez, Marcos

29/03/20226:00:0034
29/03/20227Uchuva NaturalRodríguez, Marcos0:50:00150

Gutierrez, Jhon Jairo

29/03/20226:30:0033.6
29/03/20223Uchuva NaturalRodríguez, Marcos1:20:00150

Gutierrez, Jhon Jairo

29/03/20227:00:0034

 

1 ACCEPTED SOLUTION

@valentinaliac 
Sorry it was too late yesterday and I could not have the chance to open my computer. Yes actually I thought about that the first time. This is why I mentioned the day overlapping in my previous reply. I was expecting a feedback from you on your preferences.

It seems to me that everyday the last tray is inserted into the oven at 1:20am the next morning. I was thinking at that tome to shift the time let's say by 2 hours in order to keep all the try entry's within the same date. I followed that anyway in this solution. Please check it and let me know. Here is the updated file https://www.dropbox.com/t/668GBAJkOHeq0y9W

I've created a new column for adjusted date to overcome the day overlap issue and will use this column in both report and measure

ENTRY DATE = 
VAR AdjustedEntryTime =
    'Table'[ENTRY DATE/TIME] - TIME ( 2, 0, 0 )
RETURN
    DATE ( YEAR ( AdjustedEntryTime ), MONTH ( AdjustedEntryTime ), DAY ( AdjustedEntryTime ) )
ENTRY DATE/TIME = 'Table'[DATE] + 'Table'[ENTRY HOUR] - 1
OUTPUT DATE/TIME = 'Table'[OUTPUT DATE] + 'Table'[OUTPUT HOUR] - 1


And the measure is

Operating Hours = 
FORMAT ( 
    SUMX ( 
        VALUES ( 'Table'[ENTRY DATE] ),
        CALCULATE ( 
            MAX ( 'Table'[OUTPUT DATE/TIME] ) - MIN ( 'Table'[ENTRY DATE/TIME] )
        )
    ),
    "hh:mm"
)

1.png

 

View solution in original post

7 REPLIES 7
Anonymous
Not applicable

Hi  @valentinaliac ,

Here are the steps you can follow:

1. Create measure.

Hour =
var _mindate=
MAX('Table'[DATE])+MinX(FILTER(ALL('Table'),'Table'[DATE]=MAX('Table'[DATE])),
'Table'[ENTRY HOUR])
var _maxdate=
MAX('Table'[DATE]) +MaxX(FILTER(ALL('Table'),'Table'[DATE]=MAX('Table'[DATE])),
'Table'[ENTRY HOUR])
return
DATEDIFF(_mindate,_maxdate,HOUR)

2. Result:

vyangliumsft_0-1649125226063.png

Please click here for the pbix file

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

valentinaliac
Frequent Visitor

Hi @tamerj1 

Thank you for your quick response! The thing is that there are overlaped times. While some trays are entering, some others are going out. So, if i do what you say, it would result in pretty much hours than the real amount... 

Hi @valentinaliac 
Here is a sample file https://www.dropbox.com/t/kQCM1e2S9VTtMVXn
You are 100% correct. However I'm still confused about the days overlapping as the oven works overnight. However I made it the simple way.
I've added two calculated columns joing date and time for both entry and output

 

ENTRY DATE/TIME = 'Table'[DATE] + 'Table'[ENTRY HOUR] - 1
OUTPUT DATE/TIME = 'Table'[OUTPUT DATE] + 'Table'[OUTPUT HOUR] - 1

 

Then the measure would be

 

Operating Hours = 
FORMAT ( 
    SUMX ( 
        VALUES ( 'Table'[DATE] ),
        CALCULATE ( 
            MAX ( 'Table'[OUTPUT DATE/TIME] ) - MIN ( 'Table'[ENTRY DATE/TIME] )
        )
    ),
    "hh:mm"
)

 

Untitled.png

Hi @tamerj1 

Thank you again for your quick response. I studied the doc you send me and It's awesome. May I ask, you know if its possible to filter 2 columns instead of only 1? Because it is filtering only with the column [DATE] and keeps mixing days. For example, for the day 29/03/2022, I think the program took the last value of [DATE] 29/03/2022 where its OUTPUT DATE/TIME is 30/03/2022 5:30 and substracted the first value of [DATE] 29/03/2022 0:20, then the result is 5:10. But if you noticed, the last value of 29/03/2022 is 7:00...

@valentinaliac 
Sorry it was too late yesterday and I could not have the chance to open my computer. Yes actually I thought about that the first time. This is why I mentioned the day overlapping in my previous reply. I was expecting a feedback from you on your preferences.

It seems to me that everyday the last tray is inserted into the oven at 1:20am the next morning. I was thinking at that tome to shift the time let's say by 2 hours in order to keep all the try entry's within the same date. I followed that anyway in this solution. Please check it and let me know. Here is the updated file https://www.dropbox.com/t/668GBAJkOHeq0y9W

I've created a new column for adjusted date to overcome the day overlap issue and will use this column in both report and measure

ENTRY DATE = 
VAR AdjustedEntryTime =
    'Table'[ENTRY DATE/TIME] - TIME ( 2, 0, 0 )
RETURN
    DATE ( YEAR ( AdjustedEntryTime ), MONTH ( AdjustedEntryTime ), DAY ( AdjustedEntryTime ) )
ENTRY DATE/TIME = 'Table'[DATE] + 'Table'[ENTRY HOUR] - 1
OUTPUT DATE/TIME = 'Table'[OUTPUT DATE] + 'Table'[OUTPUT HOUR] - 1


And the measure is

Operating Hours = 
FORMAT ( 
    SUMX ( 
        VALUES ( 'Table'[ENTRY DATE] ),
        CALCULATE ( 
            MAX ( 'Table'[OUTPUT DATE/TIME] ) - MIN ( 'Table'[ENTRY DATE/TIME] )
        )
    ),
    "hh:mm"
)

1.png

 

@valentinaliac 

I'll look into it and get back to you soon

tamerj1
Community Champion
Community Champion

@valentinaliac 

You can use this measure in a matrix vidual with dates on rows

 

Operation Time =
SUMX ( Table, Table[OUTPUT HOUR] - Table[INPUT HOUR] )

 

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.