Skip to main content
Announcements
Live today at 11 AM ET. Get your questions about Qlik Connect answered, or just listen in. SIGN UP NOW
cancel
Showing results for 
Search instead for 
Did you mean: 
richters
Partner - Contributor III
Partner - Contributor III

How to get last row having the same ID

Hi all,

until now I could always get the last record by using peek(...,-1) or previous(). But now I need the last record where my field 'EbeneID' is the same. So I load data like this (just ignore the text is always the same, just for showing issues):

IDEbeneIDText
11some Text
22some Text
33some Text
42some Text
51some Text
62some Text
73some Text
81some Text

Now I want to get the text of the previous record with the same EbeneID without order the table by EbeneID (in real the table is much bigger, and it is not really an ID, its all about HTML-Code, so it is not possible to order the table and get the right text each!)

I need something like:
previous(text where previous(EbeneID) = EbeneID) , sure this doesn't work

Thanks in advance!

1 Solution

Accepted Solutions
nstefaniuk
Creator III
Creator III

15 Replies
Jason_Michaelides
Luminary Alumni
Luminary Alumni

Just to be clear - please post what your output table should be given the above input table.

richters
Partner - Contributor III
Partner - Contributor III
Author

Hi, here you are:

IDEbeneIDTextPrevTextWithSameID
11some Text ID1some Text ID1
22some Text ID2some Text ID2
33some Text ID3some Text ID3
42some Text ID4some Text ID2
51some Text ID5some Text ID1
62some Text ID6some Text ID2
73some Text ID7some Text ID3
81some Text ID8some Text ID1

I just added the ID to the Text so that it is very clear. Surely the last column should come from the Text-Column.

Jason_Michaelides
Luminary Alumni
Luminary Alumni

Got it. Try this:

Data:

LOAD

     ID

     ,EbeneID

     ,Text

FROM .....;

JOIN (Data)

LOAD

     EbeneID

     ,FirstValue(Text)     AS     PrevTextWithSameID

RESIDENT Data

GROUP BY EbeneID;

Hope this helps,

Jason

richters
Partner - Contributor III
Partner - Contributor III
Author

Well, this would always reference to the first Text of the ID but what I am searching is the reference to the text before, because it might change.

Jason_Michaelides
Luminary Alumni
Luminary Alumni

In that case wouldn't your output table be like this:

IDEbeneIDTextPrevTextWithSameID
11some Text ID1some Text ID1
22some Text ID2some Text ID2
33some Text ID3some Text ID3
42some Text ID4some Text ID2
51some Text ID5some Text ID1
62some Text ID6some Text ID4
73some Text ID7some Text ID3
81some Text ID8some Text ID5

Note my changes to rows 6 and 8.

Jason.

richters
Partner - Contributor III
Partner - Contributor III
Author

You are totally right, sorry for that

Jason_Michaelides
Luminary Alumni
Luminary Alumni

No worries.  Can't see an obvious solution but maybe something with Peek() and a resetting variable using ID or RowNo()...or maybe look at FieldValue() or FieldIndex().

I will try and come back to this later but I need to get on with my own work now I'm afriad!

Jason

richters
Partner - Contributor III
Partner - Contributor III
Author

Thanks, I will go on trying

nstefaniuk
Creator III
Creator III

2 solutions on the fly (I guess you need to calculate it on the fly, not in script)

Finding the ID is easy, but retrieving the corresponding text is harder