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

Announcements
Want to see what's currently in public preview? We've pulled it all together in one place. Check it out here
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Load table modifying the structure

I have a database in excel like this structure:

To modificate.PNG

And I need to load this in a qlikview's table to stay like this:

Modificated.PNG

Anyone can help me? Thanks.

Labels (1)
1 Solution

Accepted Solutions
luciancotea
Specialist
Specialist

Table1:

LOAD Register, Field1, Field2,

     if(peek(Register) <> Register and Register <> 'info', RowNo(), if(isnull(peek(ID)), 1, peek(ID)) ) as ID

FROM [Book1.xlsx] (ooxml, embedded labels, table is Sheet1);

 

Table2:

LOAD Field1 as Date_Start, Field2 as Date_End, ID

RESIDENT Table1 WHERE Register = 'date';    

   

left join

LOAD ID, Field1 as Worker, num(Field2) as Value

RESIDENT Table1 WHERE Register = 'info';

 

drop table Table1;

drop field ID;

View solution in original post

3 Replies
Anonymous
Not applicable
Author

You can loop through each record in turn, and:

1. if the record is a date

   - set variables to store the start and end date

2. if the record is not a date

   - add record to a new table using the stored start and end date

To do the loop you would need to test the number of records first.

This would look something like this:

NewTable:

LOAD * INLINE [ RowKey ];

OriginalTable:

LOAD

     Register,

     Field1,

     Field2

FROM .... your spreadsheet

LET vRowCount = NoOfRows('Register');

SET a = 0;

DO WHILE a <= (vRowCount-1)

LET LoopType = peek('Register',a,'OriginalTable');

IF LoopType = 'date' THEN

  LET vStartDate = peek('Field1',a,'OriginalTable');

  LET vEndDate = peek('Field2',a,'OriginalTable');

ELSE

  LET vWorker = peek('Field1',a,'OriginalTable');

  LET vValue = peek('Field2',a,'OriginalTable');

  CONCATENATE (NewTable)

  LOAD

       RowNo() AS RowKey,

       '$(vStartDate)' AS StartDate,

       '$(vEndDate)' AS EndDate,

       '$(vWorker)' AS Worker,

       '$(vValue)' AS Value

  AUTOGENERATE 1;

ENDIF

LET a = a + 1;

LOOP

Jonathan

luciancotea
Specialist
Specialist

Table1:

LOAD Register, Field1, Field2,

     if(peek(Register) <> Register and Register <> 'info', RowNo(), if(isnull(peek(ID)), 1, peek(ID)) ) as ID

FROM [Book1.xlsx] (ooxml, embedded labels, table is Sheet1);

 

Table2:

LOAD Field1 as Date_Start, Field2 as Date_End, ID

RESIDENT Table1 WHERE Register = 'date';    

   

left join

LOAD ID, Field1 as Worker, num(Field2) as Value

RESIDENT Table1 WHERE Register = 'info';

 

drop table Table1;

drop field ID;

Not applicable
Author

Perfect Lucian Cotea, this works!! Thanks