<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Pivot table - dynamic sorting using variables - identifying # dimensions in chart in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/Pivot-table-dynamic-sorting-using-variables-identifying/m-p/304823#M1183087</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi DV,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Apologies re the delay in posting the app, had a bit of tweaking still to be done and then I got side tracked onto other tasks...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The attach uses a dynamic report and then applies your macro to enable a user to display the data in the report according to their needs (ie select an expression to sort by, and whether ascending or descending)....&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Kind regards,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Rich&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Tue, 21 Feb 2012 15:47:00 GMT</pubDate>
    <dc:creator />
    <dc:date>2012-02-21T15:47:00Z</dc:date>
    <item>
      <title>Pivot table - dynamic sorting using variables - identifying # dimensions in chart</title>
      <link>https://community.qlik.com/t5/QlikView/Pivot-table-dynamic-sorting-using-variables-identifying/m-p/304818#M1183082</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi All,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Am currently trying to build a user defined sorting option within a pivot table using variables.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;ie I would like the user to be able to define which expression (volume, value, delta to previous year etc...) they would like the data to be sorted (ascending / descending) by, by using variables. &lt;/P&gt;&lt;P&gt;For a static report (ie one where the number of dimensions included are known), I have managed to get this to work, through re-engineering a solution posted on these forums.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Due to the fact that I want to combine this functionality within a dynamic report, where the number of dimensions will vary depending on user selection, I need to edit my macro so that it recognises that there are X dimensions, and therefore sorts all X dimensions by the user selection...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 8pt;"&gt;For some reason, not all my code is being returned when I attempt to copy and paste into Internet Explorer, but is similar to the below:&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 8pt;"&gt; &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 8pt;"&gt;sub SortMultiple&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 8pt;"&gt;set chart = ActiveDocument.GetSheetObject("DynamicReport2")&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 8pt;"&gt;set r = ActiveDocument.Variables("SortName")&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 8pt;"&gt;set s = ActiveDocument.Variables("SortExpression")&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 8pt;"&gt;set prop = chart.GetProperties&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 8pt;"&gt; &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 8pt;"&gt; &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 8pt;"&gt;prop.Dimensions(0).SortCriteria.SortByNumeric = 0&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 8pt;"&gt;prop.Dimensions(1).SortCriteria.SortByNumeric = 0&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 8pt;"&gt; &lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 8pt;"&gt;if s.GetContent.string = "Value" then&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 8pt;"&gt;prop.Dimensions(0).SortCriteria.Expression.v "=sum(Euros)"&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 8pt;"&gt;&lt;STRONG style="font-size: 8pt;"&gt;prop.Dimensions(1).SortCriteria.Expression.v "=sum(Euros)"&lt;/STRONG&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 8pt;"&gt;&lt;STRONG style="font-size: 8pt;"&gt;else&lt;/STRONG&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 8pt;"&gt;prop.Dimensions(0).SortCriteria.Expression.v "=sum(QtyKG)"&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 8pt;"&gt;&lt;STRONG style="font-size: 8pt;"&gt;prop.Dimensions(1).SortCriteria.Expression.v "=sum(QtyKG)"&lt;/STRONG&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 8pt;"&gt;&lt;STRONG style="font-size: 8pt;"&gt;end if&lt;/STRONG&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 8pt;"&gt;&lt;STRONG style="font-size: 8pt;"&gt; &lt;/STRONG&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 8pt;"&gt;&lt;STRONG style="font-size: 8pt;"&gt;if r.GetContent.string = "Desc" then&lt;/STRONG&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 8pt;"&gt;&lt;STRONG style="font-size: 8pt;"&gt;prop.Dimensions(0).SortCriteria.SortByExpression = 1&lt;/STRONG&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 8pt;"&gt;&lt;STRONG style="font-size: 8pt;"&gt;&lt;STRONG style="font-size: 8pt;"&gt;&lt;STRONG style="font-size: 8pt;"&gt;prop.Dimensions(1).SortCriteria.SortByExpression = 1&lt;/STRONG&gt;&lt;/STRONG&gt;&lt;/STRONG&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 8pt;"&gt;&lt;STRONG style="font-size: 8pt;"&gt;chart.SetProperties prop&lt;/STRONG&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 8pt;"&gt;&lt;STRONG style="font-size: 8pt;"&gt;r.SetContent "Asc", true&lt;/STRONG&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 8pt;"&gt;&lt;STRONG style="font-size: 8pt;"&gt;else&lt;/STRONG&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 8pt;"&gt;&lt;STRONG style="font-size: 8pt;"&gt;prop.Dimensions(0).SortCriteria.SortByExpression = -1&lt;/STRONG&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 8pt;"&gt;&lt;STRONG style="font-size: 8pt;"&gt;&lt;STRONG style="font-size: 8pt;"&gt;&lt;STRONG style="font-size: 8pt;"&gt;prop.Dimensions(1).SortCriteria.SortByExpression = -1&lt;/STRONG&gt;&lt;/STRONG&gt;&lt;/STRONG&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 8pt;"&gt;&lt;STRONG style="font-size: 8pt;"&gt;&lt;STRONG style="font-size: 8pt;"&gt;&lt;STRONG style="font-size: 8pt;"&gt;chart.SetProperties prop&lt;/STRONG&gt;&lt;/STRONG&gt;&lt;/STRONG&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 8pt;"&gt;&lt;STRONG style="font-size: 8pt;"&gt;&lt;STRONG style="font-size: 8pt;"&gt;&lt;STRONG style="font-size: 8pt;"&gt;r.SetContent "Desc", true&lt;/STRONG&gt;&lt;/STRONG&gt;&lt;/STRONG&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 8pt;"&gt;&lt;STRONG style="font-size: 8pt;"&gt;&lt;STRONG style="font-size: 8pt;"&gt;&lt;STRONG style="font-size: 8pt;"&gt;end if&lt;/STRONG&gt;&lt;/STRONG&gt;&lt;/STRONG&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 8pt;"&gt;&lt;STRONG style="font-size: 8pt;"&gt;&lt;STRONG style="font-size: 8pt;"&gt;&lt;STRONG style="font-size: 8pt;"&gt;end sub&lt;/STRONG&gt;&lt;/STRONG&gt;&lt;/STRONG&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 8pt;"&gt;&lt;STRONG style="font-size: 8pt;"&gt;&lt;STRONG style="font-size: 8pt;"&gt;&lt;STRONG style="font-size: 8pt;"&gt; &lt;/STRONG&gt;&lt;/STRONG&gt;&lt;/STRONG&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 8pt;"&gt;&lt;STRONG style="font-size: 8pt;"&gt;&lt;STRONG style="font-size: 8pt;"&gt;&lt;STRONG style="font-size: 8pt;"&gt; &lt;/STRONG&gt;&lt;/STRONG&gt;&lt;/STRONG&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 8pt;"&gt;&lt;STRONG style="font-size: 8pt;"&gt;&lt;STRONG style="font-size: 8pt;"&gt;&lt;STRONG style="font-size: 8pt;"&gt;Would like to adapt the above formula so that it returns "prop.Dimensions(i)" and then loops around for the number of Dimensions ( i), but unsure how to write this...?&lt;/STRONG&gt;&lt;/STRONG&gt;&lt;/STRONG&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 8pt;"&gt;&lt;STRONG style="font-size: 8pt;"&gt;&lt;STRONG style="font-size: 8pt;"&gt;&lt;STRONG style="font-size: 8pt;"&gt; &lt;/STRONG&gt;&lt;/STRONG&gt;&lt;/STRONG&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 8pt;"&gt;&lt;STRONG style="font-size: 8pt;"&gt;&lt;STRONG style="font-size: 8pt;"&gt;&lt;STRONG style="font-size: 8pt;"&gt;Anyone with any thoughts, greatly appreciated!&lt;/STRONG&gt;&lt;/STRONG&gt;&lt;/STRONG&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 8pt;"&gt;&lt;STRONG style="font-size: 8pt;"&gt;&lt;STRONG style="font-size: 8pt;"&gt;&lt;STRONG style="font-size: 8pt;"&gt; &lt;/STRONG&gt;&lt;/STRONG&gt;&lt;/STRONG&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 8pt;"&gt;&lt;STRONG style="font-size: 8pt;"&gt;&lt;STRONG style="font-size: 8pt;"&gt;&lt;STRONG style="font-size: 8pt;"&gt;Kind regards,&lt;/STRONG&gt;&lt;/STRONG&gt;&lt;/STRONG&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 8pt;"&gt;&lt;STRONG style="font-size: 8pt;"&gt;&lt;STRONG style="font-size: 8pt;"&gt;&lt;STRONG style="font-size: 8pt;"&gt; &lt;/STRONG&gt;&lt;/STRONG&gt;&lt;/STRONG&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-size: 8pt;"&gt;&lt;STRONG style="font-size: 8pt;"&gt;&lt;STRONG style="font-size: 8pt;"&gt;&lt;STRONG style="font-size: 8pt;"&gt;Rich&lt;/STRONG&gt;&lt;/STRONG&gt;&lt;/STRONG&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 15 Dec 2011 17:05:00 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Pivot-table-dynamic-sorting-using-variables-identifying/m-p/304818#M1183082</guid>
      <dc:creator />
      <dc:date>2011-12-15T17:05:00Z</dc:date>
    </item>
    <item>
      <title>Pivot table - dynamic sorting using variables - identifying # dimensions in chart</title>
      <link>https://community.qlik.com/t5/QlikView/Pivot-table-dynamic-sorting-using-variables-identifying/m-p/304819#M1183083</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;could someone kindly help me with my VBA syntax....?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Kind regards,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Rich&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 20 Dec 2011 12:37:50 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Pivot-table-dynamic-sorting-using-variables-identifying/m-p/304819#M1183083</guid>
      <dc:creator />
      <dc:date>2011-12-20T12:37:50Z</dc:date>
    </item>
    <item>
      <title>Re: Pivot table - dynamic sorting using variables - identifying # dimensions in chart</title>
      <link>https://community.qlik.com/t5/QlikView/Pivot-table-dynamic-sorting-using-variables-identifying/m-p/304820#M1183084</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;EM style="font-family: trebuchet ms,geneva;"&gt;Hi Rich,&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM style="font-family: trebuchet ms,geneva;"&gt;Here you go... I hope this what you needed. &lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM style="font-family: trebuchet ms,geneva;"&gt;The below procedures calculates the number of dimensions and assigns the count to variable MyDim. You can take this two step further, I mean you can do the same for experssion and dynamically count and add the experssion for sorting. Then you can change the code to generic code so that it works with any chart intead of using the chart name as literal.&lt;BR /&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM style="color: #000080; font-family: trebuchet ms,geneva;"&gt;&lt;BR /&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM style="color: #800080; font-family: trebuchet ms,geneva;"&gt;'----------------------------------------- Parent Procedure ----------------------------------------------&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM style="color: #800080; font-family: trebuchet ms,geneva;"&gt;Public Sub SetObjectToVariables ()&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM style="color: #800080; font-family: trebuchet ms,geneva;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Set MyGraph = ActiveDocument.GetSheetObject("DynamicReport2")&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 'Assigning the Chart to the variable MyGraph&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM style="color: #800080; font-family: trebuchet ms,geneva;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Set MyDims = MyGraph.GetProperties.Dimensions&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 'Assigning the Chart Dimension Properties to the Variable MyDims&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM style="color: #800080; font-family: trebuchet ms,geneva;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Set MyExps = MyGraph.GetProperties.Expressions&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 'Assigning the Chart Expression Properties to the Variable MyExps&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM style="color: #800080; font-family: trebuchet ms,geneva;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; Set MyGraphProp = MyGraph.GetProperties&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 'Assigning the Chart Preoperties to the Variable MyGraphProp&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM style="color: #800080; font-family: trebuchet ms,geneva;"&gt;End Sub&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM style="color: #800080; font-family: trebuchet ms,geneva;"&gt;'--------------------------------------------------------------------------------------------------------------------&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM style="color: #000080; font-family: trebuchet ms,geneva;"&gt;'----------------------------------------- Calling Procedure ----------------------------------------------&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM style="color: #000080; font-family: trebuchet ms,geneva;"&gt;Sub SortName&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM style="color: #000080; font-family: trebuchet ms,geneva;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; set chart = ActiveDocument.GetSheetObject("DynamicReport")&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM style="color: #000080; font-family: trebuchet ms,geneva;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; set r = ActiveDocument.Variables("SortName")&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM style="color: #000080; font-family: trebuchet ms,geneva;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; set s = ActiveDocument.Variables("SortExpression")&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM style="color: #000080; font-family: trebuchet ms,geneva;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; set prop = chart.GetProperties&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM style="color: #000080; font-family: trebuchet ms,geneva;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; prop.Dimensions(0).SortCriteria.SortByNumeric = 0&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM style="color: #000080; font-family: trebuchet ms,geneva;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if s.GetContent.string = "Value" then&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM style="color: #000080; font-family: trebuchet ms,geneva;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; prop.Dimensions(0).SortCriteria.Expression.v = "=sum(Euros)"&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM style="color: #000080; font-family: trebuchet ms,geneva;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; else&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM style="color: #000080; font-family: trebuchet ms,geneva;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; prop.Dimensions(0).SortCriteria.Expression.v = "=sum(QtyKG)"&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM style="color: #000080; font-family: trebuchet ms,geneva;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end if&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM style="color: #000080; font-family: trebuchet ms,geneva;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; if r.GetContent.string = "Desc" then&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM style="color: #000080; font-family: trebuchet ms,geneva;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; For i=0 to MyDims.Count&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM style="color: #000080; font-family: trebuchet ms,geneva;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; prop.Dimensions(i).SortCriteria.SortByExpression = 1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 'ascending&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM style="color: #000080; font-family: trebuchet ms,geneva;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; chart.SetProperties prop&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM style="color: #000080; font-family: trebuchet ms,geneva;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; r.SetContent "Asc", true&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM style="color: #000080; font-family: trebuchet ms,geneva;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; i = i + 1&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM style="color: #000080; font-family: trebuchet ms,geneva;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Next&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM style="color: #000080; font-family: trebuchet ms,geneva;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; else&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM style="color: #000080; font-family: trebuchet ms,geneva;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; For i=0 to MyDims.Count&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM style="color: #000080; font-family: trebuchet ms,geneva;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; prop.Dimensions(0).SortCriteria.SortByExpression = -1&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; 'descending &lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM style="color: #000080; font-family: trebuchet ms,geneva;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; chart.SetProperties prop&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM style="color: #000080; font-family: trebuchet ms,geneva;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; r.SetContent "Desc", true&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM style="color: #000080; font-family: trebuchet ms,geneva;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; i = i + 1&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM style="color: #000080; font-family: trebuchet ms,geneva;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Next&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM style="color: #000080; font-family: trebuchet ms,geneva;"&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; end if&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM style="color: #000080; font-family: trebuchet ms,geneva;"&gt;end sub&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM style="color: #000080; font-family: trebuchet ms,geneva;"&gt;'-----------------------------------------------------------------------------------------------------------------------&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM style="font-family: trebuchet ms,geneva;"&gt;I totally agree with Steve that is not recommended to use the VBA/VB Scripting approach but I have solved many real life problems using this VB Scripting. So I have love and hate relationship with VBA since my Excel days. I am not sure if VB Scripting in QlikView supports full OOP concepts but I am sure it support object model concept. I always create public procedure &amp;amp; functions outside my calling procedure and call the procedures or functions wherever required by passing the parameters. I am not sure if we can still call it inheritence in OOP concepts. I dont come from computers background so please bear with my ignorance.&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM style="font-family: trebuchet ms,geneva;"&gt;I hope this helps!&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM style="font-family: trebuchet ms,geneva;"&gt;Let me know if you need anything more in VBA. I'd love to do contribute.&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM style="font-family: trebuchet ms,geneva;"&gt;Good luck.&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM style="font-family: trebuchet ms,geneva;"&gt;Cheers - DV&lt;/EM&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 20 Dec 2011 15:08:44 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Pivot-table-dynamic-sorting-using-variables-identifying/m-p/304820#M1183084</guid>
      <dc:creator>IAMDV</dc:creator>
      <dc:date>2011-12-20T15:08:44Z</dc:date>
    </item>
    <item>
      <title>Re: Pivot table - dynamic sorting using variables - identifying # dimensions in chart</title>
      <link>https://community.qlik.com/t5/QlikView/Pivot-table-dynamic-sorting-using-variables-identifying/m-p/304821#M1183085</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;EM&gt;Hi Rich,&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Have you got this working? I am curious to know.&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Thanks,&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;DV&lt;/EM&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 22 Dec 2011 12:39:30 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Pivot-table-dynamic-sorting-using-variables-identifying/m-p/304821#M1183085</guid>
      <dc:creator>IAMDV</dc:creator>
      <dc:date>2011-12-22T12:39:30Z</dc:date>
    </item>
    <item>
      <title>Re: Pivot table - dynamic sorting using variables - identifying # dimensions in chart</title>
      <link>https://community.qlik.com/t5/QlikView/Pivot-table-dynamic-sorting-using-variables-identifying/m-p/304822#M1183086</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;SPAN style="font-family: trebuchet ms,geneva;"&gt;&lt;EM&gt;Hi Rich,&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: trebuchet ms,geneva;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: trebuchet ms,geneva;"&gt;&lt;EM&gt;I am posting the working example here. So that other users can benefit the solution. Please can you mark this thread as answered? I hope its okay.&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: trebuchet ms,geneva;"&gt; &lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN style="font-family: trebuchet ms,geneva;"&gt;&lt;EM&gt;Thanks,&lt;/EM&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG style="font-family: trebuchet ms,geneva;"&gt;&lt;EM&gt;DV&lt;/EM&gt;&lt;/STRONG&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 22 Dec 2011 14:16:56 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Pivot-table-dynamic-sorting-using-variables-identifying/m-p/304822#M1183086</guid>
      <dc:creator>IAMDV</dc:creator>
      <dc:date>2011-12-22T14:16:56Z</dc:date>
    </item>
    <item>
      <title>Re: Pivot table - dynamic sorting using variables - identifying # dimensions in chart</title>
      <link>https://community.qlik.com/t5/QlikView/Pivot-table-dynamic-sorting-using-variables-identifying/m-p/304823#M1183087</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Hi DV,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Apologies re the delay in posting the app, had a bit of tweaking still to be done and then I got side tracked onto other tasks...&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The attach uses a dynamic report and then applies your macro to enable a user to display the data in the report according to their needs (ie select an expression to sort by, and whether ascending or descending)....&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Kind regards,&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Rich&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Tue, 21 Feb 2012 15:47:00 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Pivot-table-dynamic-sorting-using-variables-identifying/m-p/304823#M1183087</guid>
      <dc:creator />
      <dc:date>2012-02-21T15:47:00Z</dc:date>
    </item>
    <item>
      <title>Re: Pivot table - dynamic sorting using variables - identifying # dimensions in chart</title>
      <link>https://community.qlik.com/t5/QlikView/Pivot-table-dynamic-sorting-using-variables-identifying/m-p/304824#M1183088</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;&lt;EM&gt;Hi Rich,&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Nice one. Thank for taking time to share. I like this done of sorting.&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;Cheers - DV&lt;/EM&gt;&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 22 Feb 2012 10:13:47 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Pivot-table-dynamic-sorting-using-variables-identifying/m-p/304824#M1183088</guid>
      <dc:creator>IAMDV</dc:creator>
      <dc:date>2012-02-22T10:13:47Z</dc:date>
    </item>
    <item>
      <title>Re: Pivot table - dynamic sorting using variables - identifying # dimensions in chart</title>
      <link>https://community.qlik.com/t5/QlikView/Pivot-table-dynamic-sorting-using-variables-identifying/m-p/2078040#M1223930</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/35618"&gt;@IAMDV&lt;/a&gt;&amp;nbsp;,&lt;/P&gt;
&lt;P&gt;Thanks for coming up with this. I am looking for a similar solution but I have more than a dozen Expressions that I would like to use for sorting. Some of these expressions are calculated off of other expressions.&amp;nbsp; Any idea how can the Macro be modified so that it picks up the expression names and formulae.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 30 May 2023 21:34:18 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Pivot-table-dynamic-sorting-using-variables-identifying/m-p/2078040#M1223930</guid>
      <dc:creator>AB108</dc:creator>
      <dc:date>2023-05-30T21:34:18Z</dc:date>
    </item>
  </channel>
</rss>

