Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Variable in Script - Assign Value based on If Statement

Hi there,

I'm hoping this is an easy question, but i've never created variables in my script before so just after some help.

I have an average sales calculation in one of my reports that requires a dynamic value as part of the formula.

This value needs to change depending on the current Financial Period (Period 1-12 which represent Months)

Let's name this changing value "vSalesAverageCalc"

I have a variable that has been created in the past, which picks up the current Financial Period (vReportCurrent_Period)

What I need in my script is the following logical statement: (rough idea - I know this incorrect syntax)

If vReportCurrent_Period is 1,2 or 3, Let vSalesAverageCalc = 24

If vReportCurrent_Period is 4,5 or 6 Let vSalesAverageCalc = 15

If vReportCurrent_Period is 7,8 or 9 Let vSalesAverageCalc = 18

If vReportCurrent_Period is 10,11 or 12 Let vSalesAverageCalc = 21


is someone able to help me with this syntax for this variable?


and should the variable already exist in the .qvw or is it created dynamically when the script runs?


Thanks in advance everybody!!


Cheers - Fab


12 Replies
Anonymous
Not applicable
Author

Thanks Vish I appreciate that...

you have answered the original question so I will close this thread and mark it as answered...

I will open a new question about this one...

Thanks again!!

vishsaggi
Champion III
Champion III

No problem. And can you post a sample app or guide me to the new post you created.

Anonymous
Not applicable
Author

Hi Vish,

Thanks a lot for your interest...

here's the new post regarding my issue dividing by the resultant of that variable you help me define.

Divide dimension by Variable in a script

I would like to share a sample QVW, but my script refers to my ODBC database...

Is there a way to create a sample QVW and include some of my data within the qvw instead of trying to pull it down from a database via ODBC?

Thanks

Fab