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

Announcements
Join us to spark ideas for how to put the latest capabilities into action. Register here!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

For loop issue

Hi All,

Objective is i have 2 columns:

TaskName     Comments

a b c                qwerty

a b c                asdfgh

a b c                zxcvbn

desired result is below:

TaskName     Comments

a b c               qwerty

                    asdfgh

                    zxcvbn

for this i am using For loop in script and comparing 2 variables by using If statement like below:

if $(a) = $(b) ;

the values in the variables is as below:

If a b c = a b c

Now i get Script line error due to spacing. How to overcome this problem?

thanks in advance

Sukhwant

1 Solution

Accepted Solutions
el_aprendiz111
Specialist
Specialist

Hi,

tbl:

LOAD * Inline

[

TaskName,Comments

a b c ,qwerty

a b c ,asdfgh

a b c ,zxcvbn

];

NoConcatenate

SUMARY:

LOAD

TaskName,

IF(Peek('TaskName')=TaskName,'',TaskName) AS TaskNam,

Comments

Resident tbl;

DROP Table tbl;

peek.png

View solution in original post

8 Replies
sunny_talwar

Why don't you try with Previous/Peek?

Table:

LOAD TaskName,

          Comments

FROM Source;

FinalTable:

NoConcatenate

LOAD If(Previous(TaskName) <> TaskName, TaskName) as TaskName,

          Comments

Resident Table;

DROP Table Table;

rupamjyotidas
Specialist
Specialist

Define your variable as PurgeChar('Taskname',' ')

Not applicable
Author

yes it removed the spaces, but still it is giving same Syntax line error:

If abc = abc

thanks

rupamjyotidas
Specialist
Specialist

Can you provide the whole for loop statement you have written. Although what stalwar1‌ has suggested should work for you.

Not applicable
Author

comments:

NoConcatenate

load

  Distinct PurgeChar([Task Name],' ') as ctn    

    

from capacity.qvd (qvd)

where Daterecord = '$(vtoday)' and Status = 'WIP';

comments1:

NoConcatenate

load

  Distinct ctn    

    

Resident comments;

drop Table comments;

commentstest:

NoConcatenate

load

     Distinct PurgeChar([Task Name],' ') as tn,

     Comments as c,

     Daterecord as dr

    

from capacity.qvd (qvd)

where Daterecord >= '$(vlastrundate)' and Status = 'WIP';

commentstest1:

NoConcatenate

load

      Distinct tn,

      c

    

resident  commentstest

order by tn asc, dr desc;

drop table commentstest;

let i=0;

let comm='';

FOR i=1 to NoOfRows ('comments1')-1

  let tn =  FieldValue('ctn',$(i));

  let j=0;

  For j = 1 to NoOfRows ('commentstest1')-1

  let tn1 =  FieldValue('tn',$(i));

  if $(tn) = $(tn1) ;

  let comm = $(comm) + FieldValue('c',$(i));

  TRACE $(comm);

  ENDIF

  Next

Next

Not sure Sunny's suggestion will work for me in my future needs as i want to store Text values of Comments column in one variable with the original format ( which includes spaces)

Anil_Babu_Samineni

Can you post that error. Which typo error you are facing over there.

Best Anil, When applicable please mark the correct/appropriate replies as "solution" (you can mark up to 3 "solutions". Please LIKE threads if the provided solution is helpful
el_aprendiz111
Specialist
Specialist

Hi,

tbl:

LOAD * Inline

[

TaskName,Comments

a b c ,qwerty

a b c ,asdfgh

a b c ,zxcvbn

];

NoConcatenate

SUMARY:

LOAD

TaskName,

IF(Peek('TaskName')=TaskName,'',TaskName) AS TaskNam,

Comments

Resident tbl;

DROP Table tbl;

peek.png

Oleg_Troyansky
Partner Ambassador/MVP
Partner Ambassador/MVP

The error is caused by the use of the $-sign expansion for a textual field without single quotes. THe correct syntax is this:

IF '$(a)'= '$(b)' THEN ...

Cheers,

Oleg Troyansky

Learn advanced Qlik techniques in my book QlikView Your Business.

Ask me about Qlik Sense Expert Class!