Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi,
i need to calculated business hours for many date fields. there are mutiple lines of code for the same to calculate.
Can any one suggest how to reuse the same lines of code many times for different date fields.
Regards,
Grace
Put the expressions (or parts of expressions) in variables. You can put the code the creates the variables in a text file that you include in the script with the include statement: $(Include=mysharedcodefile.qvs);
This way you can include the script file in many qlikview documents. You can then use the variables in chart expressions. If you need to change something you will only have to change it in one place, in the script file. The change will be applied to any document that uses the script file after reloading the document.
You can define your global variables with logic required.
And then you can use these variables as many times you like.
Maybe user defined functions can help you here. These are defined as variables in the QlikView script, e.g.
set vDiffMonths = Round(interval(date($2) - date($1)) / 30);
set vDiffQuarters = Round(interval(date($2) - date($1)) / 90);
set vDiffMonths2 = ((YEAR(date($2))-YEAR(date($1)))*12)+(MONTH(date($2))-MONTH(date($1)));
set vDiffQuarters2 = ((YEAR(date($2))-YEAR(date($1)))*3)+(ceil(Month(date($2))/3)-ceil(Month(date($2))/3));
You would then reference the function like this:
$(vDiffMonths('12/04/2011','05/02/2012'))
You can also store them in an Excel spreadsheet that can be imported into the QVW. This makes the functions easy to manage. See the solution that Karl Pover recommends here: http://community.qlik.com/message/89749
hi, thanks for ur reply.. can u explain me how to creat that with any example...