Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Nov. 20th, Qlik Insider - Lakehouses: Driving the Future of Data & AI - PICK A SESSION
cancel
Showing results for 
Search instead for 
Did you mean: 
dominicanlauf
Contributor III
Contributor III

Sum function in a certain amount of time

Hello everybody,  

I want to calculate the running time of my machines. But I would like to sum up the production time only up to a certain time. For example, I would like to calculate the running time of the machine for the last week - but only from 6 to 21 o'clock.

I add a picture to clarify the problem. 

Currently my formula is Sum (LatheStatistics.Duration) * 24

So I calculate the total runtime, but now I would like to add only the values ​​from the right table (Sum_if) if the time is between 6 and 21 o'clock.

Thanks in advance!

How should the formula be? My biggest problem is the syntax.Lathe_Stillstand_bis.png

2 Replies
mato32188
Specialist
Specialist

Hello Dominic,

I would suggest you to do 2 things:

In script create a flag like 

if(END_TIME-floor(END_TIME)<=0.875 AND START_TIME-floor(START_TIME)>=0.25 AND END_TIME-START_TIME< 1,1,0) as Is_WithinTime

to match 6-21 interval within 1 day.

 

In expression editor

Sum ( {<Is_WithinTime = {1}>} LatheStatistics.Duration) * 24

 

BR

Martin

ECG line chart is the most important visualization in your life.
Gysbert_Wassenaar

I think you should split the start and end time fields into separate fields for the data and the time:
Date(Floor(LatheStatistics.START_TIME)) as StartDate,
Time(Frac(LatheStatistics.START_TIME)) as StartTime,
Date(Floor(LatheStatistics.END_TIME)) as EndDate,
Time(Frac(LatheStatistics.END_TIME)) as EndTime,

That's a good idea anyway because it will use less memory that way. But you can the also easily create a marker field in a preceding load for those records that have a time between 6 and 21 o'clock:
if(StartTime>=6/24 and EndTime <21/24, 1, 0) as _Flag6To21.

Once you have that flag field you can use it in an expression to filter the records:
Sum({< _Flag6To21={1}>} LatheStatistics.Duration) * 24

 


talk is cheap, supply exceeds demand