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

Announcements
Join us in Bucharest on Sept 18th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Loading only records with largest revision number

I have a set of records with revision number as shown below :

   

SNREQ_NOREV_NODepartment
1N011Dept 1
2N012Dept 1
3N021Dept 2
4N022Dept 2
5N023Dept 2
6N024Dept 3
7N031Dept 3
8N041Dept 5
9N051Dept 10
10N052Dept 10
11N053Dept 5
12N061

Dept 6

How do I load only the records with the largest revision number, i.e. only the following records are loaded into a table ?

   

SNREQ_NOREV_NODepartment
2N012Dept 1
6N024Dept 3
7N031Dept 3
8N041Dept 5
11N053Dept 5
12N061Dept 6
1 Solution

Accepted Solutions
tamilarasu
Champion
Champion

Hi CheongWeei,

You can use inner join in this case.

Data:
LOAD * INLINE [
SN, REQ_NO, REV_NO, Department
1, N01, 1, Dept 1
2, N01, 2, Dept 1
3, N02, 1, Dept 2
4, N02, 2, Dept 2
5, N02, 3, Dept 2
6, N02, 4, Dept 3
7, N03, 1, Dept 3
8, N04, 1, Dept 5
9, N05, 1, Dept 10
10, N05, 2, Dept 10
11, N05, 3, Dept 5
12, N06, 1, Dept 6
]
;


Inner Join (Data)
Load  REQ_NO, Max(REV_NO) as REV_NO
Resident Data Group by REQ_NO;


Result:

Capture.PNG

View solution in original post

9 Replies
tamilarasu
Champion
Champion

Hi CheongWeei,

You can use inner join in this case.

Data:
LOAD * INLINE [
SN, REQ_NO, REV_NO, Department
1, N01, 1, Dept 1
2, N01, 2, Dept 1
3, N02, 1, Dept 2
4, N02, 2, Dept 2
5, N02, 3, Dept 2
6, N02, 4, Dept 3
7, N03, 1, Dept 3
8, N04, 1, Dept 5
9, N05, 1, Dept 10
10, N05, 2, Dept 10
11, N05, 3, Dept 5
12, N06, 1, Dept 6
]
;


Inner Join (Data)
Load  REQ_NO, Max(REV_NO) as REV_NO
Resident Data Group by REQ_NO;


Result:

Capture.PNG

Not applicable
Author

Nagaraj gave good example

marjan_it
Creator III
Creator III

you can use it in expression like this:

if(not IsNull(  aggr(max(REV_NO),REQ_NO)),aggr(max(REV_NO),REQ_NO))

Anonymous
Not applicable
Author

Hi Nagaraj,

I just noted that my data has duplicate records . That is after loading only records with the largest revision number, there are still duplicate.

Sample of the original data

   

SNREQ_NOREV_NODepartment
1N011Dept 1
2N012Dept 1
3N012Dept 1
4N021Dept 2
5N022Dept 2
6N031Dept 2

 

After doing an inner join, I get this.

   

SNREQ_NOREV_NODepartment
2N012Dept 1
3N012Dept 1
5N022Dept 2
6N031Dept 2

What I would like to have is this

   

SNREQ_NOREV_NODepartment
2N012Dept 1
5N022Dept 2
6N031Dept 2

tamilarasu
Champion
Champion

Hello CheongWeei,

Add another inner join like below.

Data:
LOAD * INLINE [
SN, REQ_NO, REV_NO, Department
1, N01, 1, Dept 1
2, N01, 2, Dept 1
3, N01, 2, Dept 1
1, N01, 2, Dept 1
4, N02, 1, Dept 2
5, N02, 2, Dept 2
6, N03, 1, Dept 2
]
;

Inner Join (Data)
Load  REQ_NO, Max(REV_NO) as REV_NO
Resident Data Group by REQ_NO;

Inner Join (Data)
Load  REQ_NO, Min(SN) as SN
Resident Data Group by REQ_NO;

Anonymous
Not applicable
Author

Nagaraj,

Got it ! Thanks

What if the records are exactly the same, ie, there is no SN field

REQ_NO, REV_NO, Department
N01, 1, Dept 1
N01, 2, Dept 1
N01, 2, Dept 1
N01, 2, Dept 1
N02, 1, Dept 2
N02, 2, Dept 2
N03, 1, Dept 2

sunny_talwar

Is this the required output?

Capture.PNG

Using this script:

Table:

LOAD REQ_NO,

  Max(REV_NO) as REV_NO,

  FirstSortedValue(DISTINCT Department, -REV_NO) as Department

Group By REQ_NO;

LOAD * Inline [

REQ_NO, REV_NO, Department

N01, 1, Dept 1

N01, 2, Dept 1

N01, 2, Dept 1

N01, 2, Dept 1

N02, 1, Dept 2

N02, 2, Dept 2

N03, 1, Dept 2

];

tamilarasu
Champion
Champion

CheongWeei,

You can use Sunny's solution or again inner join

Data:
Load Distinct * Inline [
REQ_NO, REV_NO, Department
N01, 1, Dept 1
N01, 2, Dept 1
N01, 2, Dept 1
N01, 2, Dept 1
N02, 1, Dept 2
N02, 2, Dept 2
N03, 1, Dept 2
]
;

Inner Join (Data)
Load  REQ_NO, Max(REV_NO) as REV_NO
Resident Data Group by REQ_NO;


Result:

Capture.PNG

Anonymous
Not applicable
Author

Thanks !