Skip to main content
Announcements
NEW: Seamless Public Data Sharing with Qlik's New Anonymous Access Capability: TELL ME MORE!
cancel
Showing results for 
Search instead for 
Did you mean: 
adnan_rafiq
Partner - Creator II
Partner - Creator II

Repeating values until null.

Hi everyone.

Just wanted to pick the brains of the gurus of QV. I want to repeat a value in a column that I get in a table using script, as many times until I find a non-null value in the same a column. So for example sake consider (AS-is)

Header 1Header 2
42186AB
CD
WE
TT
RR
QS
EF
42155GH
IJ
KL
SA
AS
QW
MN

I am trying to get, (To Be)

Header 1Header 2
42186AB
42186CD
42186WE
42186TT
42186RR
42186QS
42155GH
42155IJ
42155KL
42155SA
42155
42155

I have tried ALT, PEEK and PREVIOUS but only got values to repeat twice by using PREVIOUS.

Please help

18 Replies
maxgro
MVP
MVP

It seems that previous suggestion work; this is the result with the table you posted


1.png


Source:

LOAD

  rowno() as id,

  [Header 1],

    [Header 2]

FROM

[https://community.qlik.com/thread/211171]

(html, codepage is 1252, embedded labels, table is @1);

Final:

NoConcatenate LOAD

  If(Len(Trim([Header 1]))>0,[Header 1], Peek([Header 1])) as [Header 1],

    [Header 2]

Resident Source

Order By id;

DROP Table Source;

settu_periasamy
Master III
Master III

I think, Peek is working fine..

LOAD RecNo() as Key,
if( len(trim([Header 1]))=0, peek([Header 1]),[Header 1]) as [Header 1],
[Header 2]     
FROM
[https://community.qlik.com/thread/211171]
(
html, codepage is 1252, embedded labels, table is @1) where Len([Header 2])>0;

Capture.JPG

hic
Former Employee
Former Employee

What Gysbert suggests should work.

If the values only repeat once and no more, then something else is wrong.

  • Check that you use Peek() and not Previous().
  • Check that the records are ordered correctly.
  • Check that Peek() contains the created field - the output field:
    If(Len(Trim([Header 1]))>0,[Header 1], Peek([Header 1])) as [Header 1]

See also How to populate a sparsely populated field

HIC

adnan_rafiq
Partner - Creator II
Partner - Creator II
Author

Here is excel and qvw.

settu_periasamy
Master III
Master III

As Mentioned by HIC, you need to use the output field inside the Peek.

LOAD [Report number],

    Column,

    Numbers,

    if(len(trim([Report number]))=0,Peek([Peekedcolumn]),[Report number]) as Peekedcolumn

FROM

[Book1 (3).xlsx]

(ooxml, embedded labels, table is Sheet1);

Gysbert_Wassenaar

LOAD if(len(trim([Report number]))=0,Peek([Report number]),[Report number]) as Peekedcolumn,

    Column,

    Numbers

FROM

...

You're peeking in the wrong field. Use peek(Peekedcolumn) or give the resulting field the name [Report number]


talk is cheap, supply exceeds demand
tamilarasu
Champion
Champion

Another solution (Fill option (Transformation Wizard))

LOAD [Report number],

     Column,

     Numbers

FROM

[Book1 (1).xlsx]

(ooxml, embedded labels, table is Sheet1, filters(

Replace(1, top, StrCnd(null))

));

Output:

Capture.PNG

adnan_rafiq
Partner - Creator II
Partner - Creator II
Author

Thanks Gysbert 

can you explain the logic.

Please

Gysbert_Wassenaar

See this blog post: Peek() vs Previous() – When to Use Each


talk is cheap, supply exceeds demand