Skip to main content
Announcements
NEW: Seamless Public Data Sharing with Qlik's New Anonymous Access Capability: TELL ME MORE!
cancel
Showing results for 
Search instead for 
Did you mean: 
Upali_Wijearatne
Contributor III
Contributor III

Use of Variable

Hi

I have following Variable in QV document

vSale=Sum({<Type={'SA'}>}Sales)

I want to use that variable in the following expression in my  Pivot Table

sum({<PERIODID={"<=$(=Max(PERIODID)-1)"},YEAR =,QUARTER =,MONTH =,PERIOD =>}$(vSale))

But When I write the expression it returns Zero Value. Kindly help me to rectify it

 

 

 

Labels (1)
4 Replies
kaushiknsolanki
Partner Ambassador/MVP
Partner Ambassador/MVP

Hi, you can not use Sum function within Sum function, for that you need to use the Aggr function.

https://help.qlik.com/en-US/sense/November2023/Subsystems/Hub/Content/Sense_Hub/ChartFunctions/aggr.....

Please remember to hit the 'Like' button and for helpful answers and resolutions, click on the 'Accept As Solution' button. Cheers!
BrunPierre
Partner - Master
Partner - Master

Try debugging the expression step by step.

Create a text object for $(vSale) to ensure that the variable is calculated correctly. Make sure that the field names in the set expressions are correct and exist in your data model.

Upali_Wijearatne
Contributor III
Contributor III
Author

Thanks for Your reply. However I am new to qlikview I can not figure out how write my expression' Kindly rewrite the expression to suit my requirement

Thanks

MayilVahanan

Hi

Try like below

Method 1:

VariableName:vSale
Value: Sales [Without equal sign]

sum({<PERIODID={"<=$(=Max(PERIODID)-1)"},YEAR =,QUARTER =,MONTH =,PERIOD =, Type={'SA'}>}$(vSale))

or

VariableName: vTypeSA
Value: Type={'SA'} [Without equal sign]

sum({<PERIODID={"<=$(=Max(PERIODID)-1)"},YEAR =,QUARTER =,MONTH =,PERIOD =, $(vTypeSA)>}Sales)

Both will work. If you want to use like ur variable, you need to use like blelow

sum({<PERIODID={"<=$(=Max(PERIODID)-1)"},YEAR =,QUARTER =,MONTH =,PERIOD =, Type={'SA'}>} Aggr($(vSale), urdimension))

However, i think, its not optimistic.

Thanks & Regards, Mayil Vahanan R
Please close the thread by marking correct answer & give likes if you like the post.