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

How can i assign a label for the expression creating from macro?

Hi all,

Please see the sample attachment for clear understanding.

I am creating one straight table with expression and afterwards i am creating qvd for that.

Now after loading the qvd i am getting the total expression as a field.But i want to assign a label for that expression so,that i get that label as a field in the created qvd.

How can i do this?

Thanks...

2 Replies
Not applicable
Author

Hi All,

I found the solution for the problem from API guide and i want to share this with you.

The macro code should be like this

Sub Create

set chart = ActiveDocument.ActiveSheet.CreateStraightTable

'chart.AddDimension "Sal"

chart.AddExpression "sum(Sal)"

chart.AddExpression "Avg(Sal)"

set cp = chart.GetProperties

set expr = cp.Expressions.Item(0).Item(0).Data.ExpressionVisual

set expr1 = cp.Expressions.Item(1).Item(0).Data.ExpressionVisual

expr.Label.v = "Good_Test"

expr1.Label.v = "Bad_Test"

expr.NumAdjust = 1    'center

expr.LabelAdjust = 1    'center

expr1.NumAdjust = 1    'center

expr1.LabelAdjust = 1    'center

chart.SetProperties cp

End Sub

But still i have the problem like no.of lines of code is increased if i have more no.of expressions.

So i need for loop to control this code.

Thanks...

perumal_41
Partner - Specialist II
Partner - Specialist II

Hi Ravi

'ADD the Expreesions

    set f1=ActiveDocument.Fields("Measure_UA").GetPossibleValues

       set f2=ActiveDocument.Fields("MeasureLabel_UA").GetSelectedValues

        for j=0 to f1.count-1

            Mnu1 = f1.Item(j).Text

            chart.AddExpression Mnu1

        'rename an expression label

            set p = chart.GetProperties

            set exps = p.Expressions.Item(j).Item(0).Data.ExpressionVisual

             exps.Label.v = f2.Item(j).Text

            chart.SetProperties p

        next

    p.ChartProperties.Title.Show=False

    chart.SetProperties p

End Sub

Please check this code.