<?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: run different macros depending on the value of the variable in App Development</title>
    <link>https://community.qlik.com/t5/App-Development/run-different-macros-depending-on-the-value-of-the-variable/m-p/2028520#M84741</link>
    <description>&lt;P&gt;I would think you could just reference the variable in your macro like:&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN&gt;Select ActiveDocument.Evaluate("Date(Date#(AddMonths(Today(),-&lt;STRONG&gt;$(myvar)&lt;/STRONG&gt;), 'DD.MM.YYYY'),&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;BTW,&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sat, 21 Jan 2023 17:18:47 GMT</pubDate>
    <dc:creator>rwunderlich</dc:creator>
    <dc:date>2023-01-21T17:18:47Z</dc:date>
    <item>
      <title>run different macros depending on the value of the variable</title>
      <link>https://community.qlik.com/t5/App-Development/run-different-macros-depending-on-the-value-of-the-variable/m-p/2028510#M84740</link>
      <description>&lt;P&gt;Hi&lt;BR /&gt;My problem is that I need to select a month either 1 or 2 months ago, depending on the variable v_addTimeShift, which has a value of either 1 or 2. I currently use different macros for this and run them using button actions. Unfortunately, I am unable to run different macros in the&amp;nbsp; one activity depending on the variable ( something like: If(var=1, macro1, macro2). I have tried to use the variable inside a macro as well, in this case one macro is enough, but unfortunately that doesn't work either.&amp;nbsp;The solution would also be if I could write a third macro that would run either the first or the second macro depending on the value of the variable, I tried that too, but unfortunately it didn't work.&lt;BR /&gt;Riho&lt;/P&gt;
&lt;P&gt;Sub SelectLastMonth&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;With ActiveDocument.Fields("Year_Month")&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.Select ActiveDocument.Evaluate("Date(Date#(AddMonths(Today(),-1), 'DD.MM.YYYY'), 'YYYY-MM')")&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; End With &lt;BR /&gt;End Sub&lt;/P&gt;
&lt;P&gt;Sub SelectLastMonth_L&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;With ActiveDocument.Fields("Year_Month")&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;.Select ActiveDocument.Evaluate("Date(Date#(AddMonths(Today(),-2), 'DD.MM.YYYY'), 'YYYY-MM')")&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; End With &lt;BR /&gt;End Sub&lt;/P&gt;</description>
      <pubDate>Sat, 21 Jan 2023 14:46:57 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/run-different-macros-depending-on-the-value-of-the-variable/m-p/2028510#M84740</guid>
      <dc:creator>riho92qv</dc:creator>
      <dc:date>2023-01-21T14:46:57Z</dc:date>
    </item>
    <item>
      <title>Re: run different macros depending on the value of the variable</title>
      <link>https://community.qlik.com/t5/App-Development/run-different-macros-depending-on-the-value-of-the-variable/m-p/2028520#M84741</link>
      <description>&lt;P&gt;I would think you could just reference the variable in your macro like:&lt;/P&gt;
&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&lt;SPAN&gt;Select ActiveDocument.Evaluate("Date(Date#(AddMonths(Today(),-&lt;STRONG&gt;$(myvar)&lt;/STRONG&gt;), 'DD.MM.YYYY'),&lt;/SPAN&gt;&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;BTW,&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sat, 21 Jan 2023 17:18:47 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/run-different-macros-depending-on-the-value-of-the-variable/m-p/2028520#M84741</guid>
      <dc:creator>rwunderlich</dc:creator>
      <dc:date>2023-01-21T17:18:47Z</dc:date>
    </item>
    <item>
      <title>Re: run different macros depending on the value of the variable</title>
      <link>https://community.qlik.com/t5/App-Development/run-different-macros-depending-on-the-value-of-the-variable/m-p/2028557#M84747</link>
      <description>&lt;P&gt;Thank you very much for your help, the advice worked. However, I also have another macro that selects the last 12 months. I also did this round following the same advice and it works too. However, this macro seems very clumsy and it should be possible to write it using the for next loop. Unfortunately, I can't get it to work. I am also attaching both versions of the macro.&lt;BR /&gt;Riho&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;FONT size="2"&gt;sub Select12months&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;With ActiveDocument.Fields("Year_Month")&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;&amp;nbsp; &amp;nbsp;.Select ActiveDocument.Evaluate("Date(Date#(AddMonths(Today(),-1-$(v_addTimeShift)), 'DD.MM.YYYY'), 'YYYY-MM')")&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;&amp;nbsp; &amp;nbsp;.ToggleSelect ActiveDocument.Evaluate("Date(Date#(AddMonths(Today(),-2-$(v_addTimeShift)), 'DD.MM.YYYY'), 'YYYY-MM')") &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;&amp;nbsp; &amp;nbsp;.ToggleSelect ActiveDocument.Evaluate("Date(Date#(AddMonths(Today(),-3-$(v_addTimeShift)), 'DD.MM.YYYY'), 'YYYY-MM')")&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;&amp;nbsp; &amp;nbsp;.ToggleSelect ActiveDocument.Evaluate("Date(Date#(AddMonths(Today(),-4-$(v_addTimeShift)), 'DD.MM.YYYY'), 'YYYY-MM')")&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;&amp;nbsp; &amp;nbsp;.ToggleSelect ActiveDocument.Evaluate("Date(Date#(AddMonths(Today(),-5-$(v_addTimeShift)), 'DD.MM.YYYY'), 'YYYY-MM')")&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;&amp;nbsp; &amp;nbsp;.ToggleSelect ActiveDocument.Evaluate("Date(Date#(AddMonths(Today(),-6-$(v_addTimeShift)), 'DD.MM.YYYY'), 'YYYY-MM')")&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;&amp;nbsp; &amp;nbsp;.ToggleSelect ActiveDocument.Evaluate("Date(Date#(AddMonths(Today(),-7-$(v_addTimeShift)), 'DD.MM.YYYY'), 'YYYY-MM')")&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;&amp;nbsp; &amp;nbsp;.ToggleSelect ActiveDocument.Evaluate("Date(Date#(AddMonths(Today(),-8-$(v_addTimeShift)), 'DD.MM.YYYY'), 'YYYY-MM')")&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;&amp;nbsp; &amp;nbsp;.ToggleSelect ActiveDocument.Evaluate("Date(Date#(AddMonths(Today(),-9-$(v_addTimeShift)), 'DD.MM.YYYY'), 'YYYY-MM')")&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;&amp;nbsp; &amp;nbsp;.ToggleSelect ActiveDocument.Evaluate("Date(Date#(AddMonths(Today(),-10-$(v_addTimeShift)), 'DD.MM.YYYY'), 'YYYY-MM')")&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;.&amp;nbsp; &amp;nbsp;ToggleSelect ActiveDocument.Evaluate("Date(Date#(AddMonths(Today(),-11-$(v_addTimeShift)), 'DD.MM.YYYY'), 'YYYY-MM')")&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;.&amp;nbsp; &amp;nbsp;ToggleSelect ActiveDocument.Evaluate("Date(Date#(AddMonths(Today(),-12-$(v_addTimeShift)), 'DD.MM.YYYY'), 'YYYY-MM')")&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;End With &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;end sub&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;sub Select12monthsTest&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;With ActiveDocument.Fields("Year_Month")&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;.Select ActiveDocument.Evaluate("Date(Date#(AddMonths(Today(),-1-$(v_addTimeShift)), 'DD.MM.YYYY'), 'YYYY-MM')")&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;for n=2 to 12&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;.ToggleSelect ActiveDocument.Evaluate("Date(Date#(AddMonths(Today(),-n-$(v_addTimeShift)), 'DD.MM.YYYY'), 'YYYY-MM')")&lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;next &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;End With &lt;/FONT&gt;&lt;BR /&gt;&lt;FONT size="2"&gt;end sub&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Sun, 22 Jan 2023 10:20:08 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/run-different-macros-depending-on-the-value-of-the-variable/m-p/2028557#M84747</guid>
      <dc:creator>riho92qv</dc:creator>
      <dc:date>2023-01-22T10:20:08Z</dc:date>
    </item>
  </channel>
</rss>

