Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
atair
Contributor II
Contributor II

Copy next Timestamp with condition

Hello friends.

I have a scenario where I need to calculate the duration of different status of devices. Status could be working, disturbance, stopped. 

All timestamps are recorded in on column. The challenge for was that when the status is Working, i.e. End.Time of a disturbance, there is a different ID.  Here there is an example of the table and the expected result:

Sample:

StatusDeviceTime.StampIDAttributeValue
Workingaa1201904122054552ReasonFixed
Disturbanceaa1201904121538481Reasonbroken
Disturbanceaa1201904121538481FaultEngine
Workingaa2201904081755544ReasonFixed
Disturbanceaa2201904081746583Reasonbroken
Disturbanceaa2201904081746583FaultPC
Workingaa1201904021858036ReasonFixed
Stoppedaa1201904021851515Reasonbroken
Workingaa2201904122054557ReasonFixed
Disturbanceaa2201904121538486Reasonbroken
Disturbanceaa2201904121538486FaultPanel
Workingaa1201904081755548ReasonFixed
Disturbanceaa1201904081746589Reasonbroken
Disturbanceaa1201904081746589FaultEngine
Workingaa22019040218580311ReasonFixed
Stoppedaa22019040218515110Reasonbroken

 

Expected:

StatusDeviceTime.StampIDAttributeValue
Workingaa1201904122054552ReasonFixed
Disturbanceaa1201904121538481End.Time20190412205455
Disturbanceaa1201904121538481Reasonbroken
Disturbanceaa1201904121538481FaultEngine
Workingaa2201904081755544ReasonFixed
Disturbanceaa2201904081746583End.Time20190408175554
Disturbanceaa2201904081746583Reasonbroken
Disturbanceaa2201904081746583FaultPC
Workingaa1201904021858036ReasonFixed
Stoppedaa1201904021851515End.Time20190402185803
Stoppedaa1201904021851515Reasonbroken
Workingaa2201904122054557ReasonFixed
Disturbanceaa2201904121538486End.Time20190412205455
Disturbanceaa2201904121538486Reasonbroken
Disturbanceaa2201904121538486FaultPanel
Workingaa1201904081755548ReasonFixed
Disturbanceaa1201904081746589End.Time20190408175554
Disturbanceaa1201904081746589Reasonbroken
Disturbanceaa1201904081746589FaultEngine
Workingaa22019040218580311ReasonFixed
Stoppedaa22019040218515110End.Time20190402185803
Stoppedaa22019040218515110Reasonbroken

 

Thanks in advance

Labels (3)
1 Solution

Accepted Solutions
lfetensini
Partner - Creator II
Partner - Creator II

Well, we need a lot work to do this... Lets Go...

 

// Extract Phase with Row Number
[TMP DATA]:
LOAD
Status,
Device,
Num(Time.Stamp) as Time.Stamp,
Num(ID) as ID,
Attribute,
Trim(Value) as Value,
RowNo() as RowID
FROM Test.xlsx(ooxml, embedded labels, table is Planilha1);

 

// Getting broken and fixed value for ID
NoConcatenate
[TMP NEW DATA]:
LOAD
Status,
Device,
Time.Stamp,
ID,
Attribute,
Value,
RowID
Resident [TMP DATA]
Where Match(Lower(Value),'fixed', 'broken')
Order By RowID;

 

// Doing End.Time
NoConcatenate
[END DATA]:
LOAD
Status,
Device,
Time.Stamp,
ID,
If(Lower(Value)='broken', 'End.Time', Attribute) as Attribute,
If(Lower(Value)='broken', Previous(Time.Stamp), Value) as Value,
RowID
Resident [TMP NEW DATA]
Order By RowID;

DROP Table [TMP NEW DATA];

 

// Inserting End.Time
Concatenate([TMP DATA])
LOAD
Status,
Device,
Time.Stamp,
ID,
Attribute,
Value,
RowID
Resident [END DATA]
Where Attribute = 'End.Time';

DROP Table [END DATA];

 

// Sorting new Table (OPTIMAL):

NoConcatenate

[DATA]:
LOAD
Status,
Device,
Time.Stamp,
ID,
Attribute,
Value
Resident [TMP DATA]
Order By
RowID;

DROP Tables [TMP DATA];

Support your colleagues. Remember to "like" the answers that are helpful to you and flag as "solved" the one that helped you solve. Cheers.

View solution in original post

1 Reply
lfetensini
Partner - Creator II
Partner - Creator II

Well, we need a lot work to do this... Lets Go...

 

// Extract Phase with Row Number
[TMP DATA]:
LOAD
Status,
Device,
Num(Time.Stamp) as Time.Stamp,
Num(ID) as ID,
Attribute,
Trim(Value) as Value,
RowNo() as RowID
FROM Test.xlsx(ooxml, embedded labels, table is Planilha1);

 

// Getting broken and fixed value for ID
NoConcatenate
[TMP NEW DATA]:
LOAD
Status,
Device,
Time.Stamp,
ID,
Attribute,
Value,
RowID
Resident [TMP DATA]
Where Match(Lower(Value),'fixed', 'broken')
Order By RowID;

 

// Doing End.Time
NoConcatenate
[END DATA]:
LOAD
Status,
Device,
Time.Stamp,
ID,
If(Lower(Value)='broken', 'End.Time', Attribute) as Attribute,
If(Lower(Value)='broken', Previous(Time.Stamp), Value) as Value,
RowID
Resident [TMP NEW DATA]
Order By RowID;

DROP Table [TMP NEW DATA];

 

// Inserting End.Time
Concatenate([TMP DATA])
LOAD
Status,
Device,
Time.Stamp,
ID,
Attribute,
Value,
RowID
Resident [END DATA]
Where Attribute = 'End.Time';

DROP Table [END DATA];

 

// Sorting new Table (OPTIMAL):

NoConcatenate

[DATA]:
LOAD
Status,
Device,
Time.Stamp,
ID,
Attribute,
Value
Resident [TMP DATA]
Order By
RowID;

DROP Tables [TMP DATA];

Support your colleagues. Remember to "like" the answers that are helpful to you and flag as "solved" the one that helped you solve. Cheers.