Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Performing LET var = only({Set analysis} Field) in a macro

Hi there!

I would like to do the following:

When the user makes a selection in a particular field I would like about 30 variables to be updated with the result of an only-statement including some set analysis. I am aware that this can be done by using the set variable functionality under field actions -> external actions 30 times, but this is a bit messy in my opinion.

So, can it be achieved using a macro? Abusing notation a bit, I would like to have 30 statements like:

LET var_i = only({$<A={"B_i"}>} Field)

I know that macros can set variables, so it is primarily the only-part with the set analysis I am wondering about.

1 Solution

Accepted Solutions
erichshiino
Partner - Master
Partner - Master

Hi,

This is the macro that you need:

sub setVariables()

dim i

for i=1 to 30

ActiveDocument.CreateVariable "var_" & i

'if your variables already exist, you dont need the line above

set v = ActiveDocument.GetVariable("var_" & i)

v.SetContent "only({$<A={B_" & i & "}>} Field)",true

next

end sub

You can call it from Actions -> External ->  Run  Macro

Hope this helps,

Erich

View solution in original post

2 Replies
erichshiino
Partner - Master
Partner - Master

Hi,

This is the macro that you need:

sub setVariables()

dim i

for i=1 to 30

ActiveDocument.CreateVariable "var_" & i

'if your variables already exist, you dont need the line above

set v = ActiveDocument.GetVariable("var_" & i)

v.SetContent "only({$<A={B_" & i & "}>} Field)",true

next

end sub

You can call it from Actions -> External ->  Run  Macro

Hope this helps,

Erich

Anonymous
Not applicable
Author

Hey, you're right! Thanks!