Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us in Toronto Sept 9th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
mhassinger
Creator
Creator

Setting variables from field selections

What I'm trying to accomplish is for the end user to be able to make selections on two fields - month and year - and to have those values be used to calculate the ending period for a rolling 12 month period. If either field has no selections, I want the ending period to be based on default values (today's month and year).

So I am starting by trying to define some variables in the load script to define what the default values are.

LET varToday = Num('1/1/2011');
LET varCurYear = Year($(varToday));
LET varCurMonth = Month($(varToday));

I have a text object on my app to test these values, and I'm already running into problems - namely that varCurMonth always appears blank. I can't seem to parse that value out correctly.

If I can get that sorted, the next problem I have is how to set them when a selection is made (it hasn't worked so far), and perhaps more importantly, how to revert the values back to the ones I had defined in the load script when those selections are cleared.

OR - am I going about this all wrong? Is there a simpler way to do this? I know I could probably simplify this a little by using one selection (MonthYear), but I prefer the UI interface of showing months and years.

1 Solution

Accepted Solutions
Not applicable

To update a selection/variable one can use triggers. Those are available from the Document Properties menu. There are multiple type of triggers one can create, but the one you are looking after is "OnChange" or "OnInput" depending on if the user directly changes that dimension or if it gets updated through it being connected to a dimension that the user changes. The trigger should include two "External -> Set Variable" rules; one for varCurYear and one for varCurMonth.

View solution in original post

3 Replies
marcel_olmo
Partner Ambassador
Partner Ambassador

Hi mhassinger, why you just don't use the function today(), it will return the current date, and you can parse it as week, month, year and anything you want.

Something like this :

LET varToday = today();
LET varCurYear = Year(today());
LET varCurMonth = Month(today());

Hope it helps!!

Not applicable

To update a selection/variable one can use triggers. Those are available from the Document Properties menu. There are multiple type of triggers one can create, but the one you are looking after is "OnChange" or "OnInput" depending on if the user directly changes that dimension or if it gets updated through it being connected to a dimension that the user changes. The trigger should include two "External -> Set Variable" rules; one for varCurYear and one for varCurMonth.

mhassinger
Creator
Creator
Author

I was able to set the variables with the triggers. I also got them to revert to a default value when they were unselected/cleared by using:

=if(count(distinct FiscalYear) > 1, 2010, FiscalYear)

in the action.

I still haven't gotten the initial default value for month to load correctly, though. Unfortunately, I can't use today(), because for my purposes the deate needs to not always be today. I need the flexibility to code a date into the load script and parse it out.

EDIT: Ok, the problem wasn't with edit script code. It was parsing fine. The text object I was using to show the variable values as a test was wrong. I had something like " & '-' & $(varCurMonth) " and I needed to put single quotes around the variable name since it was text. I'll get all this syntax down eventually!