Qlik Community

Qlik Sense App Development

Discussion board where members can learn more about Qlik Sense App Development and Usage.

joeybird
Contributor II

peek or pervious when simular number

hi

I am trying to see if next number is lower than the next...but I am having issues when it sees the first number or next

I have tried both expressions

if((Sales)< peek(sales),'1','0') as flag

if((Sales)< previous(sales),'1','0') as flag

basically

Month 1 , sales = 10     ...flag = 1

Month 2,  sales = 9.8   ... flag = 1

Month 3,  sales = 9.9  ....flag =  0

Month 4  Sales = 9.9   ... flag = 0

Month 5  Sales = 15   .... flag = 0

how can I make Month 1 flag be 0?

please help

1 Solution

Accepted Solutions
ramoncova06
Valued Contributor III

Re: peek or pervious when simular number

are your months strings or numbers ?

if they are string, then try adding a number and apply the sort on a descending way, peek or previous should work as long as you use the same field name, like Jonathan already suggested

7 Replies
MVP
MVP

Re: peek or pervious when simular number

Is the field Sales or sales - QV field names are case sensitive.

The correct syntax would be:

If(Sales < Alt(previous(Sales), 0), 1, 0) as flag,



galax_allu
Valued Contributor

Re: peek or pervious when simular number

Hi

Please find the attachement of QVF of your requirement ..

Note : I am assuming   'Sales' as field name ...

joeybird
Contributor II

Re: peek or pervious when simular number

hi

I have tried both and both give me same answer I have been getting

any other ideas please?

mark6505
Valued Contributor III

Re: peek or pervious when simular number

HI,

You need to make sure you data is orders by the month,

Then you Can do something like

IF(RowNo() = 1,

    0,

     IF(Sales < previous(Sales),

          1,

          0

          )

     ) as flag,

If you have multiple years you can add a check for year in a similar fashion

Mark

ramoncova06
Valued Contributor III

Re: peek or pervious when simular number

are your months strings or numbers ?

if they are string, then try adding a number and apply the sort on a descending way, peek or previous should work as long as you use the same field name, like Jonathan already suggested

joeybird
Contributor II

Re: peek or pervious when simular number

Hi guys

still a problem,

I am loading in from SQL tables

I have tried order by month too

I have even tried

Num(replace(Sales, ' ', '')) as Sales... to make sure it sees a number field

I am guessing its rounding the figure? because its decimal places?

please help

joeybird
Contributor II

Re: peek or pervious when simular number

Hi

after some testing ..it only works, if field is cast as an int ...not numeric

thanks guys for your help x