Skip to main content
Announcements
See what Drew Clarke has to say about the Qlik Talend Cloud launch! READ THE BLOG
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

How to make data linear?

Below is the current structure of my data and i would like that to be changes into the structure that is posted below.

DateRecnumberTo StatusFrom Status
12/1/20101ValidInValid
12/2/20101InvalidValid
12/3/20101ValidInvalid
12/3/20101InvalidValid
12/1/20102ValidValid
12/1/20103ValidInvalid


I would like this to be changed into linear data in qlikview but not sure where to start.

DateRecnumberStatus
12/1/20101Valid
12/1/20101InValid
12/2/20101Invalid
12/2/20101Valid
12/3/20101Valid
12/3/20101Invalid
12/3/20101Invalid
12/3/20101Valid
12/1/20102Valid
12/1/20103Valid
12/1/20103Invalid


1 Solution

Accepted Solutions
Not applicable
Author

Missread the table. Don't really get whats linear about the table either...

No big change of script though.

load Date,Recnumber, [To Status] as Status resident xxx;

load Date,Recnumber, [From Status] as Status resident xxx;

if you only like a record like:
"12/1/2010 2 Valid Valid"
to result in one line in the final table (seems like a likely typo). Add:

where [To Status]<>[From Status];

after the the last load statement.

If load order is important I would do the following:

temp:
load Date,Recnumber,recno() as recno,'1' as counter, [To Status] as Status resident xxx;

load Date,Recnumber,recno() as recno,'2' as counter, [From Status] as Status resident xxx;


load Date,Recnumber,Status; //think this will work. if not drop the counter and recno fields some other way.
noconcatenate load Date,Recnumber,Status,recno,counter
resident temp
order by recno,counter;

View solution in original post

10 Replies
Not applicable
Author

If load order doesnt matter you can do:

load Date,Recnumber, mid([To Status],2) as Status resident xxx;

load Date,Recnumber, [From Status] as Status resident xxx;

Not applicable
Author

Nilsberg,

I am not looking to trim the field but rather make the record linear. If you notice, I have 4 records that is related to RecNum 1 whereas the desired table should have 8 records, It is almost like looking through a record as along as there is change in status for that RecNum.

Hope this makes sense.

Thank you!!

Not applicable
Author

Missread the table. Don't really get whats linear about the table either...

No big change of script though.

load Date,Recnumber, [To Status] as Status resident xxx;

load Date,Recnumber, [From Status] as Status resident xxx;

if you only like a record like:
"12/1/2010 2 Valid Valid"
to result in one line in the final table (seems like a likely typo). Add:

where [To Status]<>[From Status];

after the the last load statement.

If load order is important I would do the following:

temp:
load Date,Recnumber,recno() as recno,'1' as counter, [To Status] as Status resident xxx;

load Date,Recnumber,recno() as recno,'2' as counter, [From Status] as Status resident xxx;


load Date,Recnumber,Status; //think this will work. if not drop the counter and recno fields some other way.
noconcatenate load Date,Recnumber,Status,recno,counter
resident temp
order by recno,counter;

Not applicable
Author

Nilsberg,

Thank you much!! 🙂 Here is how i worked this issue

Thank you.

Pranita

test2:

load

Date as DATE2,

[Recnumber] AS [Recnumber2],

[From Status] AS STATUS,

recnum as recnum2

RESIDENT TEST

where [To Status] <> [From Status];

concatenate

load

Date as DATE2,

[Recnumber] AS [Recnumber2],

[To Status] AS STATUS,

recnum as recnum2

RESIDENT TEST

where [To Status] <> [From Status];



Not applicable
Author

You are most welcome. By the way, the 'concatenate' before the last load-statement is not necessary.

Regards

//Nils

Not applicable
Author

Maybe another solution :


data:
CrossTable(V , Status,2)
Load * Inline [
Date,Recnumber,To ,From
12/1/2010 , 1, Valid , InValid
12/2/2010 ,1 , Invalid , Valid
12/3/2010 ,1 , Valid , Invalid
12/3/2010 ,1 , Invalid, Valid
12/1/2010 ,2 , Valid , Valid
12/1/2010 ,3 , Valid , Invalid];


regards

Not applicable
Author

Nil,

I have one more issue that I am trying to resolve.

Below is my daily table. From this daily table, I only want to extract the max record based on recnum and all the corresponding data into separate table. How do i go about it? Any help will be appreciated.

DAILY TABLE

DATE

recnum

STATUS

ID

STATUS_BHANGE

11/3/2010

199701

A

1

A TO B

11/3/2010

199702

B

1

A TO B

11/3/2010

200711

B

1

B TO A

11/3/2010

200712

A

1

B TO A

11/23/2010

1554971

A

1

A TO B

11/23/2010

1554972

B

1

A TO B

11/23/2010

1563321

B

1

B TO A

11/23/2010

1563322

A

1

B TO A



MAX TABLE

DATE

recnum

STATUS

ID

STATUS_BHANGE

11/23/2010

1563322

A

1

B TO A



Not applicable
Author

Hi

There is a lot of ways you can do this. I would just go with a sort. If you dont like the extra column, just peek at the first record of the sorted table (here called temp) instead of using rowno.

hope it helps

//Nils


temp:
load *,rowno() as rowno resident [DAILY TABLE] order by recnum desc;

[MAX TABLE]:
noconcatenate load DATE,recnum,STATUS,ID,STATUS_BHANGE resident temp where rowno='1';
drop table temp;


Not applicable
Author

Nil,

Once again, I my senario isn't clear. Sorry about that. I am looking for the max record group by ID.

Meaning, for each ID there are multiple possible recnums. I need to pull only th max recnum for each ID and all the corresponding data to that recnum

Hope this explains better.

Thank you.