Qlik Community

Qlik Education Discussions

Discussion Board for collaboration related to Qlik Education.

Not applicable

Setting and using variables

Hi All,

I am new to QlikView and am stuck with an issue in the script side.

I need to create a variable and store a value, only to be used by the next LOAD statement.

Here is how it goes.

FACT:

LOAD fields from FACT.qvd;

SET CYEAR=FACT.FISCAL_YEAR;

DIM:

IF($(CYEAR)-DIM.FISCAL_YEAR=0,DIM.FISCAL_WEEK,0)

FROM DIM.qvd;

The issue is that the $(CYEAR) is replaced by FACT.FISCAL_YEAR when the application is refreshed. And it pops up an error message that the field is not found.

Thanks for your help..

Tags (2)
1 Solution

Accepted Solutions
its_anandrjs
Not applicable

Re: Setting and using variables

Hi,

For load value from any table use Peek() and for storing use LET rather than SET

FACT:

LOAD fields from FACT.qvd;

LET CYEAR = Peek('FACT.FISCAL_YEAR',-1,'FACT');

DIM:

IF($(CYEAR)-DIM.FISCAL_YEAR=0,DIM.FISCAL_WEEK,0)

FROM DIM.qvd;

Note:- And what value you need in the variable CYEAR i suppose max year if the order of table is ascending then you get max year value, otherwise provide sample file.

Regards

Anand

4 Replies
alexandros17
Not applicable

Re: Setting and using variables

Try LET instead of SET ...

let me know

its_anandrjs
Not applicable

Re: Setting and using variables

Hi,

For load value from any table use Peek() and for storing use LET rather than SET

FACT:

LOAD fields from FACT.qvd;

LET CYEAR = Peek('FACT.FISCAL_YEAR',-1,'FACT');

DIM:

IF($(CYEAR)-DIM.FISCAL_YEAR=0,DIM.FISCAL_WEEK,0)

FROM DIM.qvd;

Note:- And what value you need in the variable CYEAR i suppose max year if the order of table is ascending then you get max year value, otherwise provide sample file.

Regards

Anand

Not applicable

Re: Setting and using variables

LET worked in loading the application with no errors but the data was not as expected.

PEEK worked perfectly.Thanks for your help.

Not applicable

Re: Setting and using variables

Thanks Anand.

Worked like a charm..

Community Browser