Qlik Community

New to Qlik Sense

Discussion board where members can get started with Qlik Sense.

Announcements
Qlik® Product Spotlight: Discover what’s possible. Get more from our products.
See for yourself. Register today.
eduardo_dimperi
Not applicable

Number of rows inside a foreach

Hi everyone,

I need to get the number of rows of date (named DATEINI) to each oid_meter in my table, with this information i'll after use a loop to read every data of every oid_meter. I try the code below, but it only output me the total of date and not total of date for oid_meter.

Test:

NoConcatenate

Load Distinct

OID_METER,

Floor(DATEINI) AS DATEINI //date field

Resident Concat_table

WHERE CONSUMO=0

ORDER BY DATEINI;

FOR Each meter in FieldValueList('OID_METER')

    for vRow = 0 to (NoOfRows('Test')-1)

      

       Let vDataIni = Date(Peek('DATEINI',vRow,'Test'));

       Let vDataFim = Date(Peek('DATEINI',vRow+1,'Test'));

      

       if (Interval(vDataFim-vDataIni,'DD')=1) then

       Count_Int=$(Count_Int)+1;

       endif

       vData[$(vRow)] = $(vDataIni);

       vCount[$(vRow)]= $(Count_Int);

     next

NEXT meter

There is anyway to replace NoOfRows('Test') for some function that return numer of rows of DATEINI in the current section(current OID_METER) ?

Thanks

1 Solution

Accepted Solutions
Gysbert_Wassenaar
Not applicable

Re: Number of rows inside a foreach

Yes. Inside the outer For loop create a temporary table with the records you want the count of. Use the NoOfRows function on that temporary table for the inner For loop. At the end of the outer loop drop that temporary table again so you can recreate it for the new OID_METER value in the next iteration.


talk is cheap, supply exceeds demand
2 Replies
Gysbert_Wassenaar
Not applicable

Re: Number of rows inside a foreach

Yes. Inside the outer For loop create a temporary table with the records you want the count of. Use the NoOfRows function on that temporary table for the inner For loop. At the end of the outer loop drop that temporary table again so you can recreate it for the new OID_METER value in the next iteration.


talk is cheap, supply exceeds demand
eduardo_dimperi
Not applicable

Re: Number of rows inside a foreach

Gysbert, thank you for your help