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: 
New-Qlik
Creator III
Creator III

How to call variable in set analysis

Hi

I have a variable and I want to call it in set analysis for YTD

example variable name is Var1

set analysis

sum({<DateField={">=$(=(YearStart(Max(DateField),0,4)))<=$(=YearEnd(Max(DateField),0,4))"},Year=,Month=>}$(Var1))


but its not working .

5 Replies
Arthur_Fong
Partner - Specialist III
Partner - Specialist III

Hi Avneet,

Please attach a sample qvw.

Thanks and regards,

Arthur Fong

OmarBenSalem

what does sum($(var1)) returns in a KPI?

and what does the var1 contains?

How it is defined?

New-Qlik
Creator III
Creator III
Author

var1 contains calculation like

sum((sales/weight) * xyz) / sum(xyz)

agigliotti
Partner - Champion
Partner - Champion

you can put your set analysis into a variable as below:

SET var1 = "{< DateField={">=$(=(YearStart(Max(DateField),0,4)))<=$(=YearEnd(Max(DateField),0,4))"},Year=,Month= >}";


and your expression become as below:

=sum( $(var1) (sales/weight) * xyz ) / sum( $(var1) xyz )


I hope it helps.

OmarBenSalem

u can't do sum of sum:

I mean :

sum(sum(sales))

u use an aggr function (sum, count, avg etc) on a "dimension"

to be able to use sum on sum: project the second sum on  a dimension so that u "tranform" it on a dimension.

I mean:

sum(aggr(sum(Sales),TheDimUsedInTheChart))


So, u can do :

sum({<DateField={">=$(=(YearStart(Max(DateField),0,4)))<=$(=YearEnd(Max(DateField),0,4))"},Year=,Month=>}

AGGR($(Var1),YourDim)

)