Skip to main content
Announcements
Qlik Introduces a New Era of Visualization! READ ALL ABOUT IT
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Count run of negative values

Hi, 

I have a dataset  with positive and negative values.  Within the dataset there is a unique identifier that start at '1' and increments by 1 for each row.  Is it possible to count the maximum occurrence of a run of negative values eg,

run_count.PNG

so using the above example I would like to show '5' in a text box the the largest consecutive run of negative values is 5..

Is this possible?

Many thanks

2 Replies
swuehl
MVP
MVP

You can maybe do it like shown here

Counters in the Load

add a preceding load:

LOAD *,

     If(Sign(Indicator) =1, DaysWithTrend,0) as DaysWithPositiveTrend,

     If(Sign(Indicator) =-1, DaysWithTrend,0) as DaysWithNegativeTrend

;

Load *,

   IfChange * Peek( Change ) > 0,

        Peek( TrendID ),

        RangeSum( 1, Peek( TrendID ))

        ) as TrendID,

   IfChange * Peek( Change ) > 0,

        RangeSum( 1, Peek( DaysWithTrend )),

        0

        ) as DaysWithTrend;

Load

   Indicator,

   Indicator - Peek( Indicator ) as Change

Resident Daily_TQM_Measurement

   Order By Date;

Then in your text box:

=Max( DaysWithNegativeTrend)

trdandamudi
Master II
Master II

May be as attached:

Count_Run_Of_Negative_Numbers.jpg