Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

Announcements

Breathe easy -- you now have more time to plan your next steps with Qlik!
QlikView 11.2 Extended Support is now valid through December 31, 2020. Click here for more information.

lf_fk_bkk
New Contributor III

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
erich_shiino
Honored Contributor

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

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

2 Replies
erich_shiino
Honored Contributor

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

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

lf_fk_bkk
New Contributor III

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

Hey, you're right! Thanks!