Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

Announcements
QlikView Fans! We’d love to hear from you.
Share your QlikView feedback with the product team… Click here to participate in our 5-minute survey.
Rules, plus terms and conditions, can be found here.
Not applicable

Create expression in Script rather than Front End

Hi guys,

This should be pretty straight forward, but it is not working as expected for me.

I have 5 expressions as follows

 

sum(C1_K)/sum({<C_Date={'<=$(=today()-1)'}>}Value)

sum(C21_K)/sum({<C_Date={'<=$(=today()-21)'}>}Value) and so on

The expressions cause my front end to slow down when this chart is displayed.

I would like to move this to the script to simp-lify the calculation.

I tried if(C_Date = today()-1, 1,0) as C1_K_Flag

When I put this back in my expression as sum(C1_K)/sum(C1_K_Flag * Value), it doesn't work and comes up with a blank chart.

Can someone please tell me what I am doing wrong?

Thanks

1 Solution

Accepted Solutions
MVP
MVP

Re: Create expression in Script rather than Front End

Your script flag is checking for C_Date equal today()-1 while your set modifer is using a date range (<=today()-1).

Could this explain something? If you don't have data for C_Date equal today()-1, all flags are zero and your expression won't return anything (div by zero).

3 Replies
Employee
Employee

Re: Create expression in Script rather than Front End

Instead of moving all calcutations to script, I could create all variables into your script with this code

for i = 1 to 31

  Let varname='vC'&i&'_K';

  Let varvalue=date(Today() - i);

  Let $(varname) = '$(varvalue)';

next

And then use

Sum(C1_K)/sum({<C_Date={'<=$(vC1_K)'}>}Value)



MVP
MVP

Re: Create expression in Script rather than Front End

Your script flag is checking for C_Date equal today()-1 while your set modifer is using a date range (<=today()-1).

Could this explain something? If you don't have data for C_Date equal today()-1, all flags are zero and your expression won't return anything (div by zero).

Not applicable

Re: Create expression in Script rather than Front End

Thanks for all the responses. Swuehl, thanks for spotting my obvious mistake. I wasn't using the right expression in my load script because I was ignoring the <= sign.

Everything works fine now.

Many thanks

Community Browser