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)
Related
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 am working on a aggregator and it contain build in functions which are I am not familiar with. Few are these I listed here, does anyone know what SQL format is it?
TODATE(string, in_format[, out_format])
ISDATEFORMAT(value[,date_format])
TOCHAR(numeric_value)
Also, here is how I use it, it does accepting my syntax, but it didn't return correct value.
count(where text_column != TODATE('date_format','YYYY-MM-DD', 'yyyymm'))
for TODATE(string, in_format[, out_format])you can use TODATE('20171114','YYYYMMDD')
for ISDATEFORMAT(value[,date_format]) ISDATEFORMAT("2017-06-15", "%M %d %Y")
and tochar function converts a number or date to a string. e.g
TO_CHAR(1210.73, '9,999.99')
Result: ' 1,210.73'
Finally I found out line of code that works:
sum(DECODE(text_column, DATETOCHAR('date_column','yyyy-mm-dd','yyyymm'),0,1))
So add on top of my original question. What type of SQL is function 'Datatochar'!?
Is there any reason that this syntax shouldn't work in Qlikview load script??
Let v_myNumber = year(today());
Let v_myString = '2017-08';
If left($(v_myString),4) = text($(v_myNumber)) Then
'do something
Else
'do something else
End If;
I've tried both ways where I convert variable string to number and evaluate against the number variable directly and this way. They won't evaluate to equivalence when they should..
Left function is expecting a string as is getting something else as a parameter. As you are currently doing, the function will be called as Left(2017-08, 4) which is unhandle by QlikView.
If you use Left('$(v_myString)',4), it will evaluate as Left('2017-08', 4) as work as expected. Just adding quotes around the variable it should work.
Although QlikView calls them variables, they should really be seen as "stuff to replaced (at sometimes evaluated) at runtime", which is slightly different from a standard "variable" behaviour.
Dollar sign expansion is a big subject, but in short:
if you are setting a variable - no need for $().
if you are using a variable - you can use $(). depends on its context.
if you are using a variable that needs to be evaluated - you have to use $().
for example in a load script: let var1 = 'if(a=1,1,2)' - here later on the script you will probably want to use this variable as $(var1) so it will be evaluated on the fly...
I hope its a little more clear now. variable can be used in many ways at even can take parameters!
for example:
var2 = $1*$2
and then you can use like this: $(var2(2,3)) which will yield 6
For further exploration of this, I would suggest reading this
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
Example from Qlikview help:
sum( {$<Year = {“>1978<2004”}>} Sales )
I try this code, but it did't works
Count( {$<Damages.DamageDate = {">Min(OtherDate)"}>} Damages.Id)
Looks like qlikview did't support dates in inequalities.
Any way if anyowne know how to do things like this please help.
As I remember, you must use a dollar-sign expansion within the set expression. Look up "Set Modifiers with Dollar-Sign Expansions" in the manual. The Min function will then be evaluated and so the set expression should work.
It will look sg like this:
Count( {$<Damages.DamageDate = {">$(=Min(OtherDate))"}>} Damages.Id)
Or perhaps
Count( {$<Damages.DamageDate = {">$(#=Min(OtherDate))"}>} Damages.Id)
I'd use
// Reopen or share this result by using the following Url:
// http://tools.qlikblog.at/SetAnalysisWizard/?sa=J0LC
Count({$<[Damages.DamageDate]={">$(=Min(OtherDate))"}>}[Damages.Id])
Note: I think you should square brackets for qualified field names like "Damages.DamageDate".
You can use the Set Analysis Wizard to change the expression.
Hope this helps!
Regards
Stefan
Another posibility to your question is create a variable for example: vMinDate = Min(OtherDate)
And then you can use your variable in the expression like this:
Count( {$<Damages.DamageDate = {'$(vMinDate)'}>} Damages.Id)
I not find the way how to calculate what I need in qlikview, but I workaround it by make all calculation in sql query.
UPDATE:
Also combination of count and if may be helpful. And don't forget place user selected values into document variables before use it in expressions