Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

How to make day fields in this particular situation?

I am having trouble with a proyect, i will give you an small example so i can explain it better.

I have this table:

AccountDateAmount
101/02/201420
102/02/201430
103/02/201450
201/02/201460
202/02/201444
203/02/201477
301/02/201498
302/02/201410
303/02/20145

And i want to make fields for every day a month can have (31). In this example i have only three but the code would be the same.

So the final table i want to create by using the table i just posted would be like this:

AccountPeriodDay1Day2Day3
1201402203050
2201402604477
320140298105

So for every period YYYYMM i have 31 different days. How can i make this happen in the script? I tried many ways but i can´t get to the result.

1 Solution

Accepted Solutions
MarcoWedel

Never give up, never surrender!

Generic load can do the trick:

QlikCommunity_Thread_117550_Pic1.JPG.jpg

QlikCommunity_Thread_117550_Pic2.JPG.jpg

tabTemp:

LOAD

  *,

  Date(MonthStart(Date), 'YYYYMM') as Period

FROM [http://community.qlik.com/thread/117550]

(html, codepage is 1252, embedded labels, table is @1);

tabTemp2:

Generic

LOAD

  Account,

  Period,

  'Day'&Day(Date) as Day,

  Amount

Resident tabTemp;

tabOutput: 

LOAD Distinct 

    Account, 

    Period  

Resident tabTemp;

DROP Table tabTemp; 

 

FOR i = 0 to NoOfTables() 

  TableList: 

  LOAD TableName($(i)) as Tablename AUTOGENERATE 1 

  WHERE WildMatch(TableName($(i)), 'tabTemp2.*'); 

NEXT i 

 

FOR i = 1 to FieldValueCount('Tablename') 

  LET vTable = FieldValue('Tablename', $(i)); 

  LEFT JOIN (tabOutput) LOAD * RESIDENT $(vTable); 

  DROP TABLE $(vTable); 

NEXT i 

 

DROP TABLE TableList; 

This script uses a generic load to create the DayX fields and a technique described by Rob Wunderlich to combine the generated tables into one: (Qlikview Notes: Use cases for Generic Load)

hope this helps

regards

Marco

View solution in original post

8 Replies
tresesco
MVP
MVP

Like this?

Load

          Day(DateField) as Day

Not applicable
Author

No, that would be too simple. That only makes the date field into the day, i need to transform the days into different columns, please see the example.

MarcoWedel

It's possible with a generic load, but you should consider creating a day-field like tresesco suggested and using this as a horizontal dimension in a pivot table.

This would visually create the table you are looking for while maintaining the possibility to select different day (as it still is a single field).

regards

Marco

tresesco
MVP
MVP

After creating the Day field, use a pivot table; take Day as third dimension; then pull Day up to column. Does this work?

PrashantSangle

Hi,

Please find enclosed file.

This will help you.

Regards,

Great dreamer's dreams never fulfilled, they are always transcended.
Please appreciate our Qlik community members by giving Kudos for sharing their time for your query. If your query is answered, please mark the topic as resolved 🙂
Not applicable
Author

Thank you all for the help, but i need the output to be a simple table, it doesn´t work for me a pivot table because I have to use the data on another aplication, so the pivot table is not the answer.

The generic load is not good for me either because i need a final table as a result and the generic load creates seperate tables.

MarcoWedel

Never give up, never surrender!

Generic load can do the trick:

QlikCommunity_Thread_117550_Pic1.JPG.jpg

QlikCommunity_Thread_117550_Pic2.JPG.jpg

tabTemp:

LOAD

  *,

  Date(MonthStart(Date), 'YYYYMM') as Period

FROM [http://community.qlik.com/thread/117550]

(html, codepage is 1252, embedded labels, table is @1);

tabTemp2:

Generic

LOAD

  Account,

  Period,

  'Day'&Day(Date) as Day,

  Amount

Resident tabTemp;

tabOutput: 

LOAD Distinct 

    Account, 

    Period  

Resident tabTemp;

DROP Table tabTemp; 

 

FOR i = 0 to NoOfTables() 

  TableList: 

  LOAD TableName($(i)) as Tablename AUTOGENERATE 1 

  WHERE WildMatch(TableName($(i)), 'tabTemp2.*'); 

NEXT i 

 

FOR i = 1 to FieldValueCount('Tablename') 

  LET vTable = FieldValue('Tablename', $(i)); 

  LEFT JOIN (tabOutput) LOAD * RESIDENT $(vTable); 

  DROP TABLE $(vTable); 

NEXT i 

 

DROP TABLE TableList; 

This script uses a generic load to create the DayX fields and a technique described by Rob Wunderlich to combine the generated tables into one: (Qlikview Notes: Use cases for Generic Load)

hope this helps

regards

Marco

Not applicable
Author

Thank you! That worked perfect!!