Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

Highlighted
lockematthewp
New Contributor

Loop in Script Help

Spoiler
 

I currently have a table with a few fields including TotalDataPoints and BadDataPoint. For example, I might have TotalDataPoints as 10 and BadDataPoint values of 2,5, and 9. I would like to make a table with all values from 1 to TotalDataPoints (20 in this example) so I can make another two fields called DataPoint and ValidPoint. This would have 'Good' unless it is equal to BadDataPoint, in which case it would be equal to 'Bad'. 

Before:

TotalDataPointsBadDataPoint
102
105
109

 

After:

TotalDataPointsDataPointValidPoint
101Good
102Bad
103Good
104Good
105Bad
106Good
107Good
108Good
109Bad
1010Good
2 Replies

Re: Loop in Script Help

May be this

Table:
LOAD TotalDataPoints,
	 BadDataPoint as DatPoint,
	 'Bad' as ValidPoint;
LOAD * INLINE [
    TotalDataPoints, BadDataPoint
    10, 2
    10, 5
    10, 9
];

Concatenate (Table)
LOAD *
Where Not Exists(DatPoint);
LOAD Distinct TotalDataPoints,
	 IterNo() as DatPoint,
	 'Good' as ValidPoint
Resident Table
While IterNo() <= TotalDataPoints;
Partner
Partner

Re: Loop in Script Help

hi

try this

FOR vDataPoint= 1 to 10

tab:
Load *,
if(match(DataPoint,2,5,9),'Bad','Good') as ValidPoint
;
Load 10 as TotalDataPoint,
$(vDataPoint) as DataPoint
AutoGenerate 1
;


NEXT