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: 
Kartik2
Partner - Creator
Partner - Creator

Ensure only numbers are used as input in 'Variable input' object

how can i ensure that only numbers are input and not text or any characters in 'Variable input'
If any text or char is used set the variable to 1.
How can we do this 

Labels (3)
1 Solution

Accepted Solutions
marcus_sommer

Yes, of course if the content of a variable is a string then needs the variable-call be adjusted. In your case maybe like:

if(isnum(num#('$(MyVar)')) or num#('$(MyVar)') = 0, 1, num#('$(MyVar)'))

View solution in original post

4 Replies
marcus_sommer

In QV there are options to enforce only certain values and especially the possibility to provide (calculated) value-lists from which the user could select the wanted value is very useful. I don't know if Sense has similar features.

Beside this you could query the variable-value and reacting on it, maybe like:

sum(Value) * $(=rangemin($(MyVar), 1))

and/or:

if(isnum($(MyVar)), 'MyVar = ' & $(MyVar), 'invalide value in MyVar')

and showing it within a title or any text-box and/or using isnum($(MyVar)) as a calculation-condition.

Kartik2
Partner - Creator
Partner - Creator
Author

Hi @marcus_sommer  , isnum() or istext() or isnull() shows error as I input nothing or any 'xyz' string in the input string.
I want to let the user input an exchange rate ,if the user puts nothing or zero or any string in that case i want the variable to be set to 1 ,so that wherever i have used that variable as a division i can see proper values.

 

 

marcus_sommer

Yes, of course if the content of a variable is a string then needs the variable-call be adjusted. In your case maybe like:

if(isnum(num#('$(MyVar)')) or num#('$(MyVar)') = 0, 1, num#('$(MyVar)'))

Kartik2
Partner - Creator
Partner - Creator
Author

Thanks @marcus_sommer , I tweaked your solution to meet my needs ,this is the working expression

if(not isnum(num#('$(vEuroRate)')) or num#('$(vEuroRate)') = 0 or isnull(num#('$(vEuroRate)')), 1, num#('$(vEuroRate)'))

 

The first one is to handle any text in the input box ,second is to handle 0 and the third is to handle null