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

Announcements
Join us to spark ideas for how to put the latest capabilities into action. Register here!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Sorting Macro

I have written this macro which is sorting the table. But sometimes it sorts in ascending order and sometimes in descending order. I want to sort only in Descending order. How that can be done ??
sub Sort
set table = ActiveDocument.GetSheetObject("CH05")
table.SortBy 6
set table = ActiveDocument.GetSheetObject("CH15")
table.SortBy 6
end sub
6 Replies
SunilChauhan
Champion II
Champion II

check this

Public Sub SortDV

    Set MyGraph = ActiveDocument.GetSheetObject("DynamicReport")            'Assigning the Chart to the variable MyGraph

    Set MyDims = MyGraph.GetProperties.Dimensions                           'Assigning the Chart Dimension Properties to the Variable MyDims

    Set MyGraphProp = MyGraph.GetProperties                                 'Assigning the Chart Preoperties to the Variable MyGraphProp

  

    set chart = ActiveDocument.GetSheetObject("DynamicReport")

    set r = ActiveDocument.Variables("SortName")

    set s = ActiveDocument.Variables("SortExpression")

    set prop = chart.GetProperties

 

    'prop.Dimensions(0).SortCriteria.SortByNumeric = 0

    if s.GetContent.string = "Value" then

    prop.Dimensions(0).SortCriteria.Expression.v = "=sum(Euros)"

    else

    prop.Dimensions(0).SortCriteria.Expression.v = "=sum(QtyKG)"

    end if

 

    if r.GetContent.string = "Desc" then

        For i=0 to MyDims.Count - 1     

            prop.Dimensions(i).SortCriteria.SortByExpression = 1        'ascending    

            chart.SetProperties prop

            r.SetContent "Asc", true

        Next

    else

        For i=0 to MyDims.Count -1      

            prop.Dimensions(i).SortCriteria.SortByExpression = -1        'descending        

            chart.SetProperties prop

            r.SetContent "Desc", true

        Next           

    end if

end sub

'----------

take help from above macro

hope this helps

Sunil Chauhan
Not applicable
Author

I am a New bee.  So i could not get your answer. Could you please simplify it a bit ??

Anonymous
Not applicable
Author

Hi

     Hope this attached qv file will be helpful for you...

     Here i use to sort the dimension using the expression. You can sort the table using sort propreties like text , orderwise, value.....

     Just refer the attached qv file macro code.

Regards

Ashok

Not applicable
Author

i dont have the licensed version of QlikView so i can not open this qvw file. Could u please post the macro that u have used ??

Anonymous
Not applicable
Author

Hi

Sub Sort

set chart=ActiveDocument.GetSheetObject("CH01")

set Prop = chart.GetProperties

set vars = Prop.Dimensions

for i = 0 to vars.Count-1

vars.Item(i).SortCriteria.SortByLoadOrder = 0

vars.Item(i).SortCriteria.SortByAscii = 0

vars.Item(i).SortCriteria.SortByFrequency = 0

vars.Item(i).SortCriteria.SortByLoadOrder = 0

vars.Item(i).SortCriteria.SortByNumeric = 0

vars.Item(i).SortCriteria.SortByState = 0

vars.Item(i).SortCriteria.SortByExpression = 0

vars.Item(i).SortCriteria.Expression.v = ""

Next

chart.SetProperties Prop

'Set your Chart dimension and Set Expression Here .

sortExpression = "sum(Sales)"

sortDimention = Inputbox ("Enter the Dimenion to sort in Desending from 0 to "&vars.Count-1)

vars.Item(sortDimention).SortCriteria.SortByExpression = -1

vars.Item(sortDimention).SortCriteria.Expression.v = sortExpression

chart.SetProperties Prop

End Sub

Regards

Ashok

SunilChauhan
Champion II
Champion II

use below code

Sub SortChart

          Set ch=ActiveDocument.GetSheetObject("CH01")                   ' You can change chartidd

          Set p = ch.GetProperties

          Set dims = p.Dimensions

          '' Dimensions start by 0

          '' 0 = Disable sort

          '' 1 = Sort ascending

          '' -1 = Sort descending

          i = dims.Item(0).SortCriteria.SortByAscii

          If i = 1 Then

                    dims.Item(0).SortCriteria.SortByAscii = -1

          Else

                    dims.Item(0).SortCriteria.SortByAscii = 1

          End If

          ch.SetProperties p

End Sub

take one button add   run this hoe this hels

Sunil Chauhan