Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik GA: Multivariate Time Series in Qlik Predict: Get Details
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Trying to convert rows to columns

Hi,

I am trying to convert data in rows to columns but with no succes. I tried some of the silutions to similar questions.

The data that needs be converted is like:

Original
Datumlogon_idactietime_stamp
1-7-2013abe118Logon8:10:18
1-7-2013abe118Logoff12:24:43
1-7-2013abe118Logon14:01:58
1-7-2013abe118Logoff14:08:15
1-7-2013abe118Logon14:29:29
1-7-2013abe118Logoff16:26:49
1-7-2013abi004Logon9:50:11
1-7-2013abi004Logoff12:44:19
1-7-2013abi004Logon13:12:37
1-7-2013abi004Logoff16:20:05

And I would like to change it to:

Wanted
Datumlogon_idLogonLogoff
1-7-2013abe1188:10:1812:24:43
1-7-2013abe11814:01:5814:08:15
1-7-2013abe11814:29:2916:26:49
1-7-2013abi0049:50:1112:44:19
1-7-2013abi00413:12:3716:20:05

The number of logon/logoff pairs can differ per id and per date.

I tried using a join but that resulted in 9 records for abe118 instead of 3

Anyone have an idea as how I should tackle it?

(btw we are still using qv 9)

1 Solution

Accepted Solutions
Gysbert_Wassenaar
Partner - Champion III
Partner - Champion III

As long as the source table is sorted by Datum, logon_id and timestamp so that a logon is always followed by a logoff you can do this:

LOAD RowNo() as id, Datum, logon_id, time_stamp as Logon

from ...sourcetable...

where actie = 'Logon';

join

LOAD RowNo() as id, Datum, logon_id, time_stamp as Logoff

from ...sourcetable...

where actie = 'Logoff';


talk is cheap, supply exceeds demand

View solution in original post

5 Replies
Gysbert_Wassenaar
Partner - Champion III
Partner - Champion III

As long as the source table is sorted by Datum, logon_id and timestamp so that a logon is always followed by a logoff you can do this:

LOAD RowNo() as id, Datum, logon_id, time_stamp as Logon

from ...sourcetable...

where actie = 'Logon';

join

LOAD RowNo() as id, Datum, logon_id, time_stamp as Logoff

from ...sourcetable...

where actie = 'Logoff';


talk is cheap, supply exceeds demand
Not applicable
Author

Test :

Load

Datum,

logon_id,

time_stamp As Logon

From.... Where actie='Logon' ;

Concatenate

Load

Datum,

logon_id,

time_stamp as Logoff

From.... Where actie='Logoff' ;

Not applicable
Author

Thank for both answers,

Both give the same reult:

Datumlogon_idLogonLogoff
1-7-2013abe1188:10:18
1-7-2013abe11814:01:58
1-7-2013abe11814:29:29
1-7-2013abe118 12:24:43
1-7-2013abe118 14:08:15
1-7-2013abe118 16:26:49

which is not what I am looking for.

In the source table the data is indeed sorted by Datum,logon_id,time_stamp and every logon is followed by a logoff

Gysbert_Wassenaar
Partner - Champion III
Partner - Champion III

Cool. I get a totally different result.

idDatumlogon_idLogonLogoff
11-7-2013abe1188:10:1812:24:43
21-7-2013abe11814:01:5814:08:15
31-7-2013abe11814:29:2916:26:49
41-7-2013abi0049:50:1112:44:19
51-7-2013abi00413:12:3716:20:05

talk is cheap, supply exceeds demand
Not applicable
Author

I found the problem.

The field Datum was originally derived from a timestamp as well so it looked like it was sorted but not quite as i expected.

I added a conversion step in between and now my results are the same as yours and I now have what I wanted.

Thanks!