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

Announcements
Qlik and ServiceNow Partner to Bring Trusted Enterprise Context into AI-Powered Workflows. Learn More!
cancel
Showing results for 
Search instead for 
Did you mean: 
Shahzad_Ahsan
Creator III
Creator III

How to get data from two tables with several condition

Hi Friends

I am stuck in a situation.

I have 2 tables say T1 and T2

T1:

IdDate
110-Oct-2017
212-Dec-2017
320-Jun-2018
410-Jul-2018
511-Jul-2018
612-Jul-2018
713-Jan-2019
814-Feb-2019
915-Mar-2019
1016-Apr-2019

 

T2:

IdAmountStatus
11001
12002
14001
22002
55002
510001
52002
58002
52001
62002
62001
66001
72001
72002
932
92001
92002
92001
102002
102001
102002

 

What I need is, if  It is current Year, then load all data and if it is previous year(here previous means, all years except current year) then load only those data whose Status=1.

The result should be like this:

IdAmountStatusDate
1100110-Oct-2017
1400110-Oct-2017
51000111-Jul-2018
5200111-Jul-2018
6200112-Jul-2018
6600112-Jul-2018
7200113-Jan-2019
7200213-Jan-2019
93215-Mar-2019
9200115-Mar-2019
9200215-Mar-2019
9200115-Mar-2019
10200216-Apr-2019
10200116-Apr-2019
10200216-Apr-2019

 

Regards

Shahzad

Labels (1)
1 Solution

Accepted Solutions
dplr-rn
Partner - Master III
Partner - Master III

Hi

try below approach

step 1 join the tables together (add a year column for simplicity)

step 2 use noconcatente and resident load previous years i.e. Year<Year(today()) and Status = 1

step 3 resident load current year i.e. Year=Year(today()) and concatenate to table in step 2 

IdListTemp:
LOAD
    Id,
    "Date",
    Year("Date") as Year
FROM [lib://Downloads/Sample_Data.xlsx]
(ooxml, embedded labels, table is Sheet2);

left join (IdListTemp)
LOAD
    Id,
    Amount,
    Status
FROM [lib://Downloads/Sample_Data.xlsx]
(ooxml, embedded labels, table is Sheet3);

NoConcatenate

IdList:
load * 
resident IdListTemp
where Year< Year(today()) and Status=1;

Concatenate (IdList)
load * 
resident IdListTemp
where Year= Year(today()) ;
drop table IdListTemp;

View solution in original post

2 Replies
dplr-rn
Partner - Master III
Partner - Master III

Hi

try below approach

step 1 join the tables together (add a year column for simplicity)

step 2 use noconcatente and resident load previous years i.e. Year<Year(today()) and Status = 1

step 3 resident load current year i.e. Year=Year(today()) and concatenate to table in step 2 

IdListTemp:
LOAD
    Id,
    "Date",
    Year("Date") as Year
FROM [lib://Downloads/Sample_Data.xlsx]
(ooxml, embedded labels, table is Sheet2);

left join (IdListTemp)
LOAD
    Id,
    Amount,
    Status
FROM [lib://Downloads/Sample_Data.xlsx]
(ooxml, embedded labels, table is Sheet3);

NoConcatenate

IdList:
load * 
resident IdListTemp
where Year< Year(today()) and Status=1;

Concatenate (IdList)
load * 
resident IdListTemp
where Year= Year(today()) ;
drop table IdListTemp;
Shahzad_Ahsan
Creator III
Creator III
Author

Hi @dplr-rn 

Thank you for your valuable reply. This is giving exact result what I needed.