Skip to main content
Announcements
See what Drew Clarke has to say about the Qlik Talend Cloud launch! READ THE BLOG
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Using a variable value to pull another field value

When I select an date in my calendar I store the value into a variable.  I want to use that variable value to pull a field value from my mastercalendar table which will give me the corresponding last year date.  Example:

mastercalendar:  'Date' = 7/12/2014 ,  'LY Date' = 7/12/2013.  In my app, I have a calendar object.  I select 7/12/2014 and that value is stored in my variable.  I want to use the variable to look in the mastercalendar table to get the LY Date.

3 Replies
Anonymous
Not applicable
Author

in the expression u can use this to get the LYYear

Only(<Date={'=$(vSelectedDate)'}>LY Date)

jpapador
Partner - Specialist
Partner - Specialist

In a list box or variable you could do:

=Addmonths(Date, -12)

This will give you the date from last year based on your selected date.

wms_manis
Partner - Contributor III
Partner - Contributor III

Here is a way to make it even more dynamic.

I build an island that looks like this:

%Unit

CurrentUnit

LastUnit

PriorUnit

Year

CY

LY

PY

Quarter

CQ

LQ

PQ

Month

CM

LM

PM

Week

CW

LW

PW

Day

CD

LD

PD

Make a list box with %Unit and make sure always one is selected.

Now I can have an expression that compares one period to the next while allowing the user to pick the period to compare:

Use two variables:

vCurPeriodSet is defined as the following:

=only(CurrentUnit)

This returns CY if year is selected or CW if Week is selected.

vLastPeriodSet is defined as the following:

=only(LastUnit)

An example of how it could be used in an expression:

sum({$< $(vCurPeriodSet)={1}>}SumValue) This gives a value for the current period selected.

Sum({$<$(vLastPeriodSet)={1}>}somevalue) returns the value from the prior period.

For the example provided, I used flags in my calendar that were built using the inYear(),inMonth() functions.  The calendar will obviously need the all the fields listed in the island you create.