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

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Looking for correct syntax to use variable in set analysis

Greetings,

I need some help finding correct syntax to use variable in set analysis.

When my expression is written as following, it works fine and returns correct value. Please note that week name "2013/33" is entered in manually.

=Num(Avg({$<[Year Week]={'2013/33'}>}Cost]),'#,##0.00')

I assigned variable to variable to find out present week's weekname and name is as "vPresentWeekName".

vPresentWeekName = Weekname(Today())

I now would like to replace "2013/33" to this new variable "vPresentWeekName" but I could not figure it out.

Following is what I tried but it does not work

Avg({<[Year Week]={$(=vPresentWeekname)}>} Cost)

Would you have any suggestions or recommendations for me? Will be much appreciated.

Best wishes,

p1907

1 Solution

Accepted Solutions
alexandros17
Partner - Champion III
Partner - Champion III

Define in the script:

LET vPresentWeekName = Weekname(Today())

then you set analyis expression will be:

=Num(Avg({$ <[Year Week]={$vPresentWeekName}>}Cost]),'#,##0.00')


View solution in original post

5 Replies
alexandros17
Partner - Champion III
Partner - Champion III

Avg({[Year Week]={'$(=vPresentWeekname)'}>} Cost)

add ' symbol ... but are you sure that Weekname(Today()) returns the value formatted as you need?

Hope it helps

Not applicable
Author

Hi Alessandro,


Thanks for your swift support and help; really appreciated.


Noted on your expression suggestion but it still returns nothing.


My variable vPresentWeekName = Weekname(Today()) returns 2013/34 for today; which is correct.

What I cannot figure out is that when I enter in the week name manually into the expression, it is working fine. Took your advice to see if variable is returning the value as intended formatting and it seems to.

Where else shall I check or what am I missing, any ideas?

By the way, I added "<" to the expression: Avg({<[Year Week]={$(=vPresentWeekname)}>} Cost)


Best wishes,


p1907



Not applicable
Author

try with below syntax

=Avg({<[Year Week]={"$(=$(vPresentWeekname))"}>} Cost)

alexandros17
Partner - Champion III
Partner - Champion III

Define in the script:

LET vPresentWeekName = Weekname(Today())

then you set analyis expression will be:

=Num(Avg({$ <[Year Week]={$vPresentWeekName}>}Cost]),'#,##0.00')


Not applicable
Author

Thank you so much, it worked!