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

Date record creation based on existing dates of MSL

Dear Community,

Your help is appreciated for the below question. Thanks in advance!!

AS shown below one MSL has Created Dates in months of june,july,december. Now i have to generate records so that each ME will have created dates > then the existing dates and less than the Max(created date) for this MSL also each ME will have Created Date month in the list of months MSL has got. and Response Score should be of latest month avaiable for that ME.

MSL IDME IDCreated DateResponse Score
1101july5
1102june4
1102july5
1103december2
1104june3
1105june6
1105december9

So in this case records generated must be as below:

Explanation: MSL Months= June, July, December. Now ME ID 101: He has record of July, so the next month in MSL list is December so in below table you see december record created.

For ME ID 102: already June, july are existing and nxt mnth in msl list is December, so this record is created in below table.

For ME ID 103: December is the latest mnth for this me and this month is the last month in MSL List. So we need not do anything for this record.

For ME ID 104: THis ME has record in june. Nxt months in the list of MSL are july and december ; so these two records are created as below.

For ME ID 105: This ME has record in june and december and no record in july hence one record of july has to be generated with june month score as shown below.

MSL IDME IDCreated DateResponse Score
1101december5
1102december5
1104july3
1104december3
1105july6

And this has to be reated for more than one MSL.

************************ Hi All Updated one more case (ME ID 105) *********************

Labels (6)
2 Replies
EmilyQiao
Contributor
Contributor

It would be better to deal with the data if the [Created Date] is a real date or a number.

Let's set the primary table as [Table1].

First, you could get such a table by script like:

[LastRecord]:

Load [MSL ID],[ME ID],max([Created Date]) as [Created Date] resident [Table1];

inner join Load * resident [Table1];

MSL IDME IDCreated DateResponse Score
110175
110275
1103122
110463

Second, you could get a cross join table for all available ME and Created Date.

[CrossTemp]:

Load distinct [Created Date] resident [Table1];

join load distinct [MSL ID],[ME ID],[Response Score] resident [LastRecord];

For example, for ME ID 101, the table should be :

MSL IDME IDCreated DateResponse Score
110175
110165
1101125
...   

Finally, you should join the [CrossTemp] with [LastRecord] to get the final result.

[RestMonth_temp]:

Load [MSL ID],[ME ID],[Created Date],[Response Score] resident [CrossTemp] ;

Ieft join Load [MSL ID],[ME ID],[Created Date] as [LastCreateDate]  resident [LastRecord];

[RestMonth]:

Load [MSL ID],[ME ID],[Created Date],[Response Score] resident [RestMonth_temp]

where [Created Date]>[LastCreateDate];

After that, drop all these temp tables except for the last [RestMonth].

Just notice that if the table concatenate wrongly, please use NoConcatenate Load.

prutis66
Contributor III
Contributor III
Author

Hi  Emilyqiao 

Thanks for your reply. I just updated question with one more test case of ME ID 105. Does your answer satisfies this case as well? Will try your script , i have been trying something in PL/SQL.

Once again thanks in advance. I Love your efforts!!  Cheers!