Skip to main content
Announcements
Qlik Connect 2025: 3 days of full immersion in data, analytics, and AI. May 13-15 | Orlando, FL: Learn More
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Macro to change the cyclic group order

Is it possible to change the order of a cyclic group by a macro (in a table). I would like to have a button to change the order of 2 dimensions in a cyclic group with 4 dimensions.

sample Cyclic group:

DIMENSION1,DIMENSION2,DIMENSION3,DIMENSION4

After pressing the button i would like to have (so 3 and 4 are changing):

DIMENSION1,DIMENSION2,DIMENSION4,DIMENSION3

If i press the button again i would have to revert to situation 1.

13 Replies
Not applicable
Author

sub ChangeCyclicGroupOrder
groups=ActiveDocument.GetGroups
gp = groups(0).GetProperties
set vars = gp.FieldDefs
fld = vars.Item(2)
if fld.Name = "DIMENSION3" then
groups(0).RemoveField 3
groups(0).RemoveField 2
groups(0).AddField "DIMENSION4"
groups(0).AddField "DIMENSION3"
else
groups(0).RemoveField 3
groups(0).RemoveField 2
groups(0).AddField "DIMENSION3"
groups(0).AddField "DIMENSION4"
end if
end sub


Not applicable
Author

Create a field in your group by formula.

For example

=

if($(vC)=1,Dimension3,Dimension4'

By pressingthe button you calculate the variable and so you you can choose your oder.

You also have to define the filed name in the same way.

Regards



Not applicable
Author

This i working Nice Arthur but now i would like to have the labels filled with text according the right dimension

so if

DIMENSION4->label test4

DIMENSION3->label test3

because of the remove and add the labels are gone

Not applicable
Author

Hello.

I expand Martin idea to use calculated dimension. In attacment is example file. Button changes variable. Variable changes dimension and label.
Best regards.

Not applicable
Author

Sorry but i'm still on personal edition so can't open a licensed qvw file!

I prefer your solution! I tried martin idea but this was not really good working for me

How can i find the code you used in your idea, i searched in the apiguide but i was not getting all the information from this sheet, is there more API information somwhere. Maybe i can find myself the code to change the group label!

Not applicable
Author

macro changes variable vC


sub ChangeVariable
if ActiveDocument.Variables("vC").GetContent.String = "1" then
ActiveDocument.Variables("vC").SetContent "0", true
else
ActiveDocument.Variables("vC").SetContent "1", true
end if
end sub


Dimension 3

=if('$(vC)'=1,DIMENSION4,DIMENSION3)


Dimension 3 label

=if('$(vC)'=1,'label test4','label test3')


Not applicable
Author

this is exactly what i tried with martins solution, but for me the latest dimension (4) was the same as dimension 3, so there was something not working, same for the labels. That is why i stepped back to your solution which is working nive, except for the labels.

Does this really work good for you, look good at the dimensions 3 and 4 if you change.

Not applicable
Author

it really works for me.

Not applicable
Author


sub changelabels
groups=ActiveDocument.GetGroups
gp = groups(0).GetProperties
set vars = gp.FieldDefs
fld = vars.Item(2)
if fld.Name = "DIMENSION3" then
dim x(3)
x(0) = "label tes1"
x(1) = "label tes2"
x(2) = "label tes3"
x(3) = "label tes4"
gp.Labels = x
groups(0).SetProperties gp
else
dim y(3)
y(0) = "label test1"
y(1) = "label test2"
y(2) = "label test4"
y(3) = "label test3"
gp.Labels = y
groups(0).SetProperties gp
end if
end sub