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: 
paulyeo11
Master
Master

Case 910 How to add partial reload with FOR Each i and Next i; ?

Hi All

I have below 2 raw data , i need to flag the latest date for field = [Opportunity Closing Date]

Below is SOURCE = SD

Company NameOpportunity Closing Date
A.E. ENGINEERS(S) PTE LTD5-Aug-20
A.E. ENGINEERS(S) PTE LTD

5-Sep-20

 

Below is SOURCE = PM

Company NameOpportunity Closing Date
ETUAN MECHATRONIC PTE LTD26-Aug-20
ETUAN MECHATRONIC PTE LTD25-Aug-20

 

i Use below script which working fine no error , But Part 2 of the script is not working :-

// Part (1)

For Each i in 'PM','SD'
Data:
LOAD
'$(i)' as SOURCE,
[Opportunity Closing Date] AS Closing_Date,
[Opportunity Closing Date],
[Opportunity Amount] AS Opp_Amount
FROM
$(vRAWPath)CRM_$(i)_.CSV
(txt, codepage is 1252, embedded labels, delimiter is ',', msq);

// Part (2)

left join(Data)
load
date(max([Opportunity Closing Date])) as [Opportunity Closing Date],
'$(i)' as SOURCE,
1 as Latest_Date_Flag
resident Data;
NEXT i;

My issue is it only work for the first loop. May i know how to make it work for second loop ? How to flag Closing Date = 26 Aug 20

Latest_Date_FlagSOURCEClosing_Date
   
-SD5-Aug-20
1SD5-Sep-20
-PM13-Aug-20
-PM24-Aug-20
-PM25-Aug-20
1PM26-Aug-20

Paul Yeo

 

1 Solution

Accepted Solutions
Kushal_Chawda

Problem is you are doing join within loop. see the below for explanation

https://community.qlik.com/t5/New-to-QlikView/left-join-in-a-loop/td-p/629005

So remove your left join code from loop and place it outside the loop

For Each i in 'PM','SD'
Data:
LOAD
'$(i)' as SOURCE,
[Opportunity Closing Date] AS Closing_Date,
[Opportunity Closing Date],
[Opportunity Amount] AS Opp_Amount
FROM
$(vRAWPath)CRM_$(i)_.CSV
(txt, codepage is 1252, embedded labels, delimiter is ',', msq);

NEXT i;

left join(Data)
load
date(max([Opportunity Closing Date])) as [Opportunity Closing Date],
SOURCE,
1 as Latest_Date_Flag
resident Data

group by SOURCE;

View solution in original post

2 Replies
Kushal_Chawda

Problem is you are doing join within loop. see the below for explanation

https://community.qlik.com/t5/New-to-QlikView/left-join-in-a-loop/td-p/629005

So remove your left join code from loop and place it outside the loop

For Each i in 'PM','SD'
Data:
LOAD
'$(i)' as SOURCE,
[Opportunity Closing Date] AS Closing_Date,
[Opportunity Closing Date],
[Opportunity Amount] AS Opp_Amount
FROM
$(vRAWPath)CRM_$(i)_.CSV
(txt, codepage is 1252, embedded labels, delimiter is ',', msq);

NEXT i;

left join(Data)
load
date(max([Opportunity Closing Date])) as [Opportunity Closing Date],
SOURCE,
1 as Latest_Date_Flag
resident Data

group by SOURCE;

paulyeo11
Master
Master
Author

Hi Kush

Thank you very much it work fine now.

Instead of Flag can you pls help me to delete those raw and on;y keep the latest date row. ( I only need those row that are Flag ) , as i actual data it does not have duplicate row . 

Ref to below table i need to flag 26 Aug and 11 Sept , where 11 sept row only have one date i also need to flag. 

Opportunity NumberOpportunity Closing DateOpportunity Name
1726-Aug-20HP SINGAPORE DDL PROJECT
1725-Aug-20HP SINGAPORE DDL PROJECT
1724-Aug-20HP SINGAPORE DDL PROJECT
1713-Aug-20HP SINGAPORE DDL PROJECT
1611-Sep-20Corning Machine Project

Paul