I am trying to use an if statement with a variable in my expression and I get no results. The variable works when I use the variable on it's own but when used with the if I get no results.
I have tried:
if(OrderQtr='Apr-Jun 2018',$(vAvgOrderCost),0)
if(OrderQtr='Apr-Jun 2018',sum($(vAvgOrderCost)),0)
sum($(vAvgOrderCost)if(OrderQtr='Apr-Jun 2018',0))
Nothing seems to work. Thanks
Variables in QlikView are used as a text replace feature, so be carefull. If your variable hold a value like 1,345 an expression like "if(OrderQtr='Apr-Jun 2018',$(vAvgOrderCost),0)" will be translated into "if(OrderQtr='Apr-Jun 2018',1,345,0)" which by itself will be a syntax error.
Something like :
Num(if(OrderQtr='Apr-Jun 2018','$(vAvgOrderCost)','0'))
would be a safe way to go.
the if() syntax should work like this if(test,true,false)
So looking at your examples I suspect this is what you are trying to do
sum(if(OrderQtr='Apr-Jun 2018',$(vAvgOrderCost),0))
I've looked through a number of tutorials and asks, and haven't found a working solution to my problem.
Suppose my dataset has two columns: sort_order and field_value. sort_order is an integer and field_value is a numerical (10,2).
I want to format some rows as #,#0 and others as #,#0.00.
Normally I would just do
iif( fields!sort_order.value = 1 or fields!sort_order.value = 23 or .....
unfortunately, the list is fairly long.
I'd like to do the equivalent of if fields!sort_order.value in (1,2,21,63,78,...) then...)
As recommended in another post, I tried the following (if sort in list, then just output a 0, else a 1. this is just to test the functionality of the IN operator):
=iif( fields!sort_order.Value IN split("1,2,3,4,5,6,8,10,11,15,16,17,18,19,20,21,26,30,31,33,34,36,37,38,41,42,44,45,46,49,50,52,53,54,57,58,59,62,63,64,67,68,70,71,75,76,77,80,81,82,92,98,99,113,115,116,120,122,123,127,130,134,136,137,143,144,146,147,148,149,154,155,156,157,162,163,164,165,170,171,172,173,183,184,185,186,192,193,194,195,201,202,203,204,210,211,212,213,263",","),0,1)
However, it doesn't look like the SSRS expression editor wants to accept the "IN" operator. Which is strange, because all the examples I've found that solve this problem use the IN operator.
Any advice?
Try using IndexOf function:
=IIF(Array.IndexOf(split("1,2,3,4,...",","),fields!sort_order.Value)>-1,0,1)
Note all values must be inside quotations.
Consider the recommendation of #Jakub, I recommend this solution if
your are feeding your report via SP and you can't touch it.
Let me know if this helps.
I am struggling with storing a set analysis expression's value in a variable.
I want to store below expression's value in a variable so that i can use that further for some calculations.
Min({< Data_Period = {'Weekly'},Formatted_Date = {'>$(=$(vSelectedWeek))'}>} Date,2)
The above expression works fine if i use it in a text box on a sheet tab. However, it is not working if i try to store its value in a variable and use that variable.
Set vW1 = Min({< Data_Period = {'Weekly'},Formatted_Date = {'>$(=$(vSelectedWeek))'}>} Date,2);
Here vSelectedWeek is being calculated as follows:
Set vSelectedWeek = Date(Weekstart(Only(BaseData_Date)),'dd/MM/YYYY');
Please advise if i am doing anything wrong or is there any other way around to achieve the same?
Thanks in advance.
If your var is truly working with that expression then try creating an input box object, define your var there and add the expression in the right column.
That should work.
If you find my answer to be pretty simple or not the way you want it, checking this link might help: https://community.qlik.com/thread/198307
I've the variable varCurrentYear
varCurrentYear = Year(Today())
And I wrote this set analysis expression
The result it’s not correct. By the way If the variable is declared in this way
varCurrentYear = 2014
The result is correct.
Why?
Thank's
I'd use
Sum({$<Year={'$(varCurrentYear)'}>}Orders)
resp without quotes if varCurrentYear is numeric
Sum({$<Year={$(varCurrentYear)}>}Orders)
See http://tools.qlikblog.at/SetAnalysisWizard/?sa=MCKA
Regards
Stefan
I know it looks strange, but you have to write:
=sum({<Year={"$(=$(varCurrentYear))" } >} Orders)
The QlikView parser can evaluate the double-nested variable for some reason.
I'd use:
=Sum({<Year={$(=varCurrentYear)}>}Orders)
Can and/or be nested in filters?
I want to filter something like this... a=1 AND ( d=NULL OR d>5 )
Can anyone help?
You can use a Lucene query string like this in elastic search:
http://www.elasticsearch.org/guide/reference/query-dsl/query-filter.html
and here is a reference to how you can use () for grouping ... one thing to note is the I found prefixing group statements with the + must have symbol returns more accurate results.
http://lucene.apache.org/java/3_2_0/queryparsersyntax.html
grouping is at the end.
... oh and if you going to use greater than RangeQuery can cover this case by
setting either the upper or lower term to null.
J.
This may be a bit late, but if anyone else is looking for this, I found that search word AND filters are easy to add. Just use more words in the query and separate them with space.
Scala Example:
val queryString = client.prepareSearch().setQuery(QueryBuilders.matchQuery("json.path.to.node", "sky car")).setSize(MAX_RESULTS)
val response = queryString.execute().actionGet()
Now response will have all results which containt both sky AND car