<?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 Set Expression/Variable shorthand based on Parameters in QlikView</title>
    <link>https://community.qlik.com/t5/QlikView/Set-Expression-Variable-shorthand-based-on-Parameters/m-p/104452#M605182</link>
    <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;So I've got a question which might be a bit of a stretch, but I want to ask you to bear with me:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'd like to standardize some of my set expressions using a basic expression template based on variables and extending those expressions with parameters (which then might get filled with their own parameters).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The way I'm approaching this is by having a couple of basic set expressions contained in variables like so:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_15319905057287154 jive_text_macro" jivemacro_uid="_15319905057287154" modifiedtitle="true"&gt;
&lt;P&gt;LET eSum.Sales = 'Sum({ $1 &amp;lt; $2 &amp;gt; }Sales)';&lt;/P&gt;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This can be defined in the load script but also in the front end, but this is just an example.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Now the first parameter is easy, this is my basic set definition, either a $ or 1, or whichever combination you prefer.&lt;/LI&gt;&lt;LI&gt;The second parameter is a bit more tricky. This could take in any value, but I would like it to work with a shorthand name for a set modifier.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. So this could be a basic implementation:&lt;/P&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_15319929580439303 jive_text_macro" jivemacro_uid="_15319929580439303" modifiedtitle="true"&gt;
&lt;P&gt;$(eSum.Sales($,))&lt;/P&gt;
&lt;P&gt;//Result: Sum({ $ &amp;lt;&amp;nbsp; &amp;gt; }Sales)&lt;/P&gt;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2. And this would be a more manual but advanced version:&lt;/P&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro _jivemacro_uid_15319930499296044" jivemacro_uid="_15319930499296044" modifiedtitle="true"&gt;
&lt;P&gt;$(eSum.Sales($, [Year]={'2018'}))&lt;/P&gt;
&lt;P&gt;//Result: Sum({ $ &amp;lt; [Year]={'2018'}&amp;gt; }Sales)&lt;/P&gt;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But now I have a table loaded with some standard set modifiers:&lt;/P&gt;&lt;TABLE border="1" class="jiveBorder" style="border: 1px solid rgb(0, 0, 0); width: 100%;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;SetShorthand&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;SetCode&lt;/STRONG&gt;&lt;/TH&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;ThisYear&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;[Year]={'$(=Max([Year]))'}&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;ThisWeek&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;[Week]={'$(=Max([Week]))'}&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now I can produce cases 1 and 2, but I would like to produce a variable which can concatenate a couple of set modifiers based on their shorthand. I have created a variable (see below) which can produce the string output of what I need, but I can't get it to work as a parameter of the first variable.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro _jivemacro_uid_15319935543133552" jivemacro_uid="_15319935543133552" modifiedtitle="true"&gt;
&lt;P&gt;// Set modifier variable&lt;/P&gt;
&lt;P&gt;LET SM = Replace(Concat({$&amp;lt;SetName={$1,$2,$3,$4,$5}&amp;gt;}DISTINCT SetDefinition, Chr(44)),Chr(35),Chr(36));&lt;/P&gt;
&lt;P&gt;// Usage:&lt;/P&gt;
&lt;P&gt;$(SM(ThisYear))&lt;/P&gt;
&lt;P&gt;// Result:&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: 13.3333px;"&gt;[Year]={'$(=Max([Year]))'}&lt;/SPAN&gt;&lt;/P&gt;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But when I try to use this variable as input for a parameter, I'm not getting the results I want. I've tried switching out the quotation signs, tried using the '=' sign for different variables and tried a couple of dollar expansions, but the best I can get is this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_1531993913373307 jive_text_macro" jivemacro_uid="_1531993913373307" modifiedtitle="true"&gt;
&lt;P&gt;// Usage: '$(eSum.Sales($,$(SM(ThisYear))}))'&lt;/P&gt;
&lt;P&gt;Sum({$ &amp;lt;Replace(Concat({$&amp;lt;SetName={ThisYear&amp;gt;}[Sales])&lt;/P&gt;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Has anybody tried this kind of variable/set expression notations or does anybody know what I'm doing wrong?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
    <pubDate>Thu, 19 Jul 2018 09:57:02 GMT</pubDate>
    <dc:creator>mpeters1988</dc:creator>
    <dc:date>2018-07-19T09:57:02Z</dc:date>
    <item>
      <title>Set Expression/Variable shorthand based on Parameters</title>
      <link>https://community.qlik.com/t5/QlikView/Set-Expression-Variable-shorthand-based-on-Parameters/m-p/104452#M605182</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;So I've got a question which might be a bit of a stretch, but I want to ask you to bear with me:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I'd like to standardize some of my set expressions using a basic expression template based on variables and extending those expressions with parameters (which then might get filled with their own parameters).&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The way I'm approaching this is by having a couple of basic set expressions contained in variables like so:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_15319905057287154 jive_text_macro" jivemacro_uid="_15319905057287154" modifiedtitle="true"&gt;
&lt;P&gt;LET eSum.Sales = 'Sum({ $1 &amp;lt; $2 &amp;gt; }Sales)';&lt;/P&gt;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This can be defined in the load script but also in the front end, but this is just an example.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;Now the first parameter is easy, this is my basic set definition, either a $ or 1, or whichever combination you prefer.&lt;/LI&gt;&lt;LI&gt;The second parameter is a bit more tricky. This could take in any value, but I would like it to work with a shorthand name for a set modifier.&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;1. So this could be a basic implementation:&lt;/P&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_15319929580439303 jive_text_macro" jivemacro_uid="_15319929580439303" modifiedtitle="true"&gt;
&lt;P&gt;$(eSum.Sales($,))&lt;/P&gt;
&lt;P&gt;//Result: Sum({ $ &amp;lt;&amp;nbsp; &amp;gt; }Sales)&lt;/P&gt;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;2. And this would be a more manual but advanced version:&lt;/P&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro _jivemacro_uid_15319930499296044" jivemacro_uid="_15319930499296044" modifiedtitle="true"&gt;
&lt;P&gt;$(eSum.Sales($, [Year]={'2018'}))&lt;/P&gt;
&lt;P&gt;//Result: Sum({ $ &amp;lt; [Year]={'2018'}&amp;gt; }Sales)&lt;/P&gt;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But now I have a table loaded with some standard set modifiers:&lt;/P&gt;&lt;TABLE border="1" class="jiveBorder" style="border: 1px solid rgb(0, 0, 0); width: 100%;"&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;SetShorthand&lt;/STRONG&gt;&lt;/TH&gt;&lt;TH style="text-align: center; background-color: #6690bc; color: #ffffff; padding: 2px;" valign="middle"&gt;&lt;STRONG&gt;SetCode&lt;/STRONG&gt;&lt;/TH&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;ThisYear&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;[Year]={'$(=Max([Year]))'}&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD style="padding: 2px;"&gt;ThisWeek&lt;/TD&gt;&lt;TD style="padding: 2px;"&gt;[Week]={'$(=Max([Week]))'}&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Now I can produce cases 1 and 2, but I would like to produce a variable which can concatenate a couple of set modifiers based on their shorthand. I have created a variable (see below) which can produce the string output of what I need, but I can't get it to work as a parameter of the first variable.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code jive_text_macro _jivemacro_uid_15319935543133552" jivemacro_uid="_15319935543133552" modifiedtitle="true"&gt;
&lt;P&gt;// Set modifier variable&lt;/P&gt;
&lt;P&gt;LET SM = Replace(Concat({$&amp;lt;SetName={$1,$2,$3,$4,$5}&amp;gt;}DISTINCT SetDefinition, Chr(44)),Chr(35),Chr(36));&lt;/P&gt;
&lt;P&gt;// Usage:&lt;/P&gt;
&lt;P&gt;$(SM(ThisYear))&lt;/P&gt;
&lt;P&gt;// Result:&lt;/P&gt;
&lt;P&gt;&lt;SPAN style="font-size: 13.3333px;"&gt;[Year]={'$(=Max([Year]))'}&lt;/SPAN&gt;&lt;/P&gt;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;But when I try to use this variable as input for a parameter, I'm not getting the results I want. I've tried switching out the quotation signs, tried using the '=' sign for different variables and tried a couple of dollar expansions, but the best I can get is this:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE __default_attr="plain" __jive_macro_name="code" class="jive_macro_code _jivemacro_uid_1531993913373307 jive_text_macro" jivemacro_uid="_1531993913373307" modifiedtitle="true"&gt;
&lt;P&gt;// Usage: '$(eSum.Sales($,$(SM(ThisYear))}))'&lt;/P&gt;
&lt;P&gt;Sum({$ &amp;lt;Replace(Concat({$&amp;lt;SetName={ThisYear&amp;gt;}[Sales])&lt;/P&gt;
&lt;/PRE&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Has anybody tried this kind of variable/set expression notations or does anybody know what I'm doing wrong?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks in advance!&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Thu, 19 Jul 2018 09:57:02 GMT</pubDate>
      <guid>https://community.qlik.com/t5/QlikView/Set-Expression-Variable-shorthand-based-on-Parameters/m-p/104452#M605182</guid>
      <dc:creator>mpeters1988</dc:creator>
      <dc:date>2018-07-19T09:57:02Z</dc:date>
    </item>
  </channel>
</rss>

