<?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>article Field selections AND-mode for Market Basket Analysis in Member Articles</title>
    <link>https://community.qlik.com/t5/Member-Articles/Field-selections-AND-mode-for-Market-Basket-Analysis/ta-p/1484761</link>
    <description>&lt;P&gt;Qlik Sense is an awesome tool when it comes to Data Discovery. However, in some situations there is no straightforward solution and one must perform a little magic with associative data model.&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;One such situation is creating Market Basket Analysis. Challenge is to enable AND functionality for user selections instead of the standard OR. What do I mean?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;Let’s use a simple sales data example. A customer buys either one product, or two or more. When we load all data it’s easy to filter orders by products.&lt;/P&gt;
&lt;P&gt;When one product is selected, we get something like this:&lt;/P&gt;
&lt;P&gt;&lt;IMG src="https://community.qlik.com/legacyfs/online/190840_1.PNG" border="0" alt="1.PNG" /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When two products are selected, we get:&lt;/P&gt;
&lt;P&gt;&lt;IMG src="https://community.qlik.com/legacyfs/online/190841_2.PNG" border="0" alt="2.PNG" /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Selecting 2 or more products will result in logical OR condition, so we get all sales records with first or second product.&lt;/P&gt;
&lt;P&gt;Data analysts working with similar (albeit much more complex) sales data are often interested in combination of products on sales orders. They need a logical AND selection to get only those records where first as well as the second product was sold.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How to achieve this behavior in Qlik Sense?&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Starting is quite easy and without any need for scripting. Using the incredible Aggr() function we can create a calculated dimension, which will count all different products sold on each order.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;IMG src="https://community.qlik.com/legacyfs/online/190842_3.PNG" border="0" alt="3.PNG" /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;When we place this dimension into a bar chart, we get a nice overview. Moreover, selecting a particular value will give us all orders where that particular count of distinct products happened.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;IMG src="https://community.qlik.com/legacyfs/online/190843_4.PNG" border="0" alt="4.PNG" /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This simple approach can help to reveal business insights which would remain hidden with standard selections in product dimension.&lt;/P&gt;
&lt;P&gt;But, let’s go a bit further. What if we want to start from a specific product and see all different sales combinations that happened?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Field Selection AND-mode&lt;/P&gt;
&lt;P&gt;We’ll have to do a bit of scripting, but all operations will be quite basic. There are two main approaches I use.&lt;/P&gt;
&lt;P&gt;First approach is really simple, flexible and great for data discovery, because all associations are nicely revealed with Qlik’s green, white and grey. One drawback is that the resulting table can grow to massive proportions with really large datasets.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. Load all orders and products again into a separate table and name the product field differently&lt;/P&gt;
&lt;P&gt;&lt;IMG src="https://community.qlik.com/legacyfs/online/190844_5.PNG" border="0" alt="5.PNG" /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2. Join the same table to the previous one and repeat it as many times as many AND selections you want. Beware that this is a cross join of products on order so think carefully about the scale of data and go step by step to see the impact on memory. I join two times in this example.&lt;/P&gt;
&lt;P&gt;&lt;IMG src="https://community.qlik.com/legacyfs/online/190845_6.PNG" border="0" alt="6.PNG" /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;3. It’s good to clean the resulting table a bit with a few conditional operations in order to dispose of irrelevant or duplicate combinations (example script is in the attached document)&lt;/P&gt;
&lt;P&gt;4. (optional) If we use IDs instead of names in previous scripts (which is recommended), then we load the product dimension (along with some categories and types for more analytical options) to a separate table for each AND field.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now we can filter Orders by product combinations and also see the next associative options:&lt;/P&gt;
&lt;P&gt;&lt;IMG src="https://community.qlik.com/legacyfs/online/190846_15.PNG" border="0" alt="15.PNG" /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Second Approach and it's variation using SET analysis&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This one is much less memory demanding, but it doesn’t provide such a nice associative experience. It’s used when working with really large datasets (100s millions of rows) along with small number of distinct entities (e.g. up to 10 products on one order), or when the sequence of entities is relevant (accounting, production, service desk etc.).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. Concatenate all different products on one order to one line&lt;/P&gt;
&lt;P&gt;&lt;IMG src="https://community.qlik.com/legacyfs/online/190847_7.PNG" border="0" alt="7.PNG" /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2. Use SubField() function to put each product to a separate field. (Create this script with a FOR...Each loop if the maximum number of distinct products on order is not known beforehand.)&lt;/P&gt;
&lt;P&gt;&lt;IMG src="https://community.qlik.com/legacyfs/online/190848_8.PNG" border="0" alt="8.PNG" /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;3. (optional) As with the previous approach it's recommended to use IDs and load separate product dimensions for each AND field.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;If all scripts were executed successfully w&lt;/SPAN&gt;e get the desired AND-mode for selections in both cases.&lt;/P&gt;
&lt;P&gt;All would be well, but there is one more requirement which is quite common – AND NOT mode. First approach will not help us with this but nothing is ever lost with Qlik. We can utilize variables and expression SET analysis along with the second approach. This basically creates a third approach &amp;gt; dynamic search in a list.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. Create a concatenated field for all distinct products on order as with the second approach&lt;/P&gt;
&lt;P&gt;2. Load product dimension again into separate tables. In our example we will have a selection for initial product(s), AND product(s) and AND NOT products.&lt;/P&gt;
&lt;P&gt;&lt;IMG src="https://community.qlik.com/legacyfs/online/190849_9.PNG" border="0" alt="9.PNG" /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;3. Create variables that will be used to construct the SET analysis in expression.&lt;/P&gt;
&lt;P&gt;- for initial products&lt;/P&gt;
&lt;P&gt;&lt;IMG src="https://community.qlik.com/legacyfs/online/190850_10.PNG" border="0" alt="10.PNG" /&gt;&lt;/P&gt;
&lt;P&gt;- for AND products&lt;/P&gt;
&lt;P&gt;&lt;IMG src="https://community.qlik.com/legacyfs/online/190851_11.PNG" border="0" alt="11.PNG" /&gt;&lt;/P&gt;
&lt;P&gt;- for AND-NOT products&lt;/P&gt;
&lt;P&gt;&lt;IMG src="https://community.qlik.com/legacyfs/online/190852_12.PNG" border="0" alt="12.PNG" /&gt;&lt;/P&gt;
&lt;P&gt;4. Finally put all variables into SET analysis of the expression used in the chart&lt;/P&gt;
&lt;P&gt;&lt;IMG src="https://community.qlik.com/legacyfs/online/190853_13.PNG" border="0" alt="13.PNG" /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This will enable AND-mode as well as AND-NOT-mode in selections.&lt;/P&gt;
&lt;P&gt;&lt;IMG src="https://community.qlik.com/legacyfs/online/190854_16.PNG" border="0" alt="16.PNG" /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Check the attached file to see all 3 approaches in action. I've been successfully using these approaches in my projects, but I’m looking forward to hearing any comments and suggestions.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Radovan&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;PS: Thanks to Mária Šándorová ( &lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/10022"&gt;@JaMajka1&lt;/a&gt;&amp;nbsp;) for suggestions.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;PPS: All challenges always have multiple solutions with Qlik. Similar functionality can be also achieved with P() and E() set functions, as described for example in this post -&amp;nbsp;&lt;A href="https://community.qlik.com/t5/Qlik-Design-Blog/Visualizing-comorbidity-Set-analysis-element-function-P/bc-p/1468751#M3621" target="_blank" rel="noopener"&gt;https://community.qlik.com/t5/Qlik-Design-Blog/Visualizing-comorbidity-Set-analysis-element-function-P/bc-p/1468751#M3621&lt;/A&gt;&lt;/P&gt;</description>
    <pubDate>Tue, 28 Jun 2022 08:34:18 GMT</pubDate>
    <dc:creator>RadovanOresky</dc:creator>
    <dc:date>2022-06-28T08:34:18Z</dc:date>
    <item>
      <title>Field selections AND-mode for Market Basket Analysis</title>
      <link>https://community.qlik.com/t5/Member-Articles/Field-selections-AND-mode-for-Market-Basket-Analysis/ta-p/1484761</link>
      <description>&lt;P&gt;Qlik Sense is an awesome tool when it comes to Data Discovery. However, in some situations there is no straightforward solution and one must perform a little magic with associative data model.&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;One such situation is creating Market Basket Analysis. Challenge is to enable AND functionality for user selections instead of the standard OR. What do I mean?&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;Let’s use a simple sales data example. A customer buys either one product, or two or more. When we load all data it’s easy to filter orders by products.&lt;/P&gt;
&lt;P&gt;When one product is selected, we get something like this:&lt;/P&gt;
&lt;P&gt;&lt;IMG src="https://community.qlik.com/legacyfs/online/190840_1.PNG" border="0" alt="1.PNG" /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;When two products are selected, we get:&lt;/P&gt;
&lt;P&gt;&lt;IMG src="https://community.qlik.com/legacyfs/online/190841_2.PNG" border="0" alt="2.PNG" /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Selecting 2 or more products will result in logical OR condition, so we get all sales records with first or second product.&lt;/P&gt;
&lt;P&gt;Data analysts working with similar (albeit much more complex) sales data are often interested in combination of products on sales orders. They need a logical AND selection to get only those records where first as well as the second product was sold.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;How to achieve this behavior in Qlik Sense?&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Starting is quite easy and without any need for scripting. Using the incredible Aggr() function we can create a calculated dimension, which will count all different products sold on each order.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;IMG src="https://community.qlik.com/legacyfs/online/190842_3.PNG" border="0" alt="3.PNG" /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;When we place this dimension into a bar chart, we get a nice overview. Moreover, selecting a particular value will give us all orders where that particular count of distinct products happened.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;&lt;IMG src="https://community.qlik.com/legacyfs/online/190843_4.PNG" border="0" alt="4.PNG" /&gt;&lt;BR /&gt;&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This simple approach can help to reveal business insights which would remain hidden with standard selections in product dimension.&lt;/P&gt;
&lt;P&gt;But, let’s go a bit further. What if we want to start from a specific product and see all different sales combinations that happened?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Field Selection AND-mode&lt;/P&gt;
&lt;P&gt;We’ll have to do a bit of scripting, but all operations will be quite basic. There are two main approaches I use.&lt;/P&gt;
&lt;P&gt;First approach is really simple, flexible and great for data discovery, because all associations are nicely revealed with Qlik’s green, white and grey. One drawback is that the resulting table can grow to massive proportions with really large datasets.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. Load all orders and products again into a separate table and name the product field differently&lt;/P&gt;
&lt;P&gt;&lt;IMG src="https://community.qlik.com/legacyfs/online/190844_5.PNG" border="0" alt="5.PNG" /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2. Join the same table to the previous one and repeat it as many times as many AND selections you want. Beware that this is a cross join of products on order so think carefully about the scale of data and go step by step to see the impact on memory. I join two times in this example.&lt;/P&gt;
&lt;P&gt;&lt;IMG src="https://community.qlik.com/legacyfs/online/190845_6.PNG" border="0" alt="6.PNG" /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;3. It’s good to clean the resulting table a bit with a few conditional operations in order to dispose of irrelevant or duplicate combinations (example script is in the attached document)&lt;/P&gt;
&lt;P&gt;4. (optional) If we use IDs instead of names in previous scripts (which is recommended), then we load the product dimension (along with some categories and types for more analytical options) to a separate table for each AND field.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Now we can filter Orders by product combinations and also see the next associative options:&lt;/P&gt;
&lt;P&gt;&lt;IMG src="https://community.qlik.com/legacyfs/online/190846_15.PNG" border="0" alt="15.PNG" /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Second Approach and it's variation using SET analysis&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This one is much less memory demanding, but it doesn’t provide such a nice associative experience. It’s used when working with really large datasets (100s millions of rows) along with small number of distinct entities (e.g. up to 10 products on one order), or when the sequence of entities is relevant (accounting, production, service desk etc.).&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. Concatenate all different products on one order to one line&lt;/P&gt;
&lt;P&gt;&lt;IMG src="https://community.qlik.com/legacyfs/online/190847_7.PNG" border="0" alt="7.PNG" /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;2. Use SubField() function to put each product to a separate field. (Create this script with a FOR...Each loop if the maximum number of distinct products on order is not known beforehand.)&lt;/P&gt;
&lt;P&gt;&lt;IMG src="https://community.qlik.com/legacyfs/online/190848_8.PNG" border="0" alt="8.PNG" /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;3. (optional) As with the previous approach it's recommended to use IDs and load separate product dimensions for each AND field.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;If all scripts were executed successfully w&lt;/SPAN&gt;e get the desired AND-mode for selections in both cases.&lt;/P&gt;
&lt;P&gt;All would be well, but there is one more requirement which is quite common – AND NOT mode. First approach will not help us with this but nothing is ever lost with Qlik. We can utilize variables and expression SET analysis along with the second approach. This basically creates a third approach &amp;gt; dynamic search in a list.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;1. Create a concatenated field for all distinct products on order as with the second approach&lt;/P&gt;
&lt;P&gt;2. Load product dimension again into separate tables. In our example we will have a selection for initial product(s), AND product(s) and AND NOT products.&lt;/P&gt;
&lt;P&gt;&lt;IMG src="https://community.qlik.com/legacyfs/online/190849_9.PNG" border="0" alt="9.PNG" /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;3. Create variables that will be used to construct the SET analysis in expression.&lt;/P&gt;
&lt;P&gt;- for initial products&lt;/P&gt;
&lt;P&gt;&lt;IMG src="https://community.qlik.com/legacyfs/online/190850_10.PNG" border="0" alt="10.PNG" /&gt;&lt;/P&gt;
&lt;P&gt;- for AND products&lt;/P&gt;
&lt;P&gt;&lt;IMG src="https://community.qlik.com/legacyfs/online/190851_11.PNG" border="0" alt="11.PNG" /&gt;&lt;/P&gt;
&lt;P&gt;- for AND-NOT products&lt;/P&gt;
&lt;P&gt;&lt;IMG src="https://community.qlik.com/legacyfs/online/190852_12.PNG" border="0" alt="12.PNG" /&gt;&lt;/P&gt;
&lt;P&gt;4. Finally put all variables into SET analysis of the expression used in the chart&lt;/P&gt;
&lt;P&gt;&lt;IMG src="https://community.qlik.com/legacyfs/online/190853_13.PNG" border="0" alt="13.PNG" /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This will enable AND-mode as well as AND-NOT-mode in selections.&lt;/P&gt;
&lt;P&gt;&lt;IMG src="https://community.qlik.com/legacyfs/online/190854_16.PNG" border="0" alt="16.PNG" /&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;Check the attached file to see all 3 approaches in action. I've been successfully using these approaches in my projects, but I’m looking forward to hearing any comments and suggestions.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Radovan&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;SPAN&gt;PS: Thanks to Mária Šándorová ( &lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/10022"&gt;@JaMajka1&lt;/a&gt;&amp;nbsp;) for suggestions.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;PPS: All challenges always have multiple solutions with Qlik. Similar functionality can be also achieved with P() and E() set functions, as described for example in this post -&amp;nbsp;&lt;A href="https://community.qlik.com/t5/Qlik-Design-Blog/Visualizing-comorbidity-Set-analysis-element-function-P/bc-p/1468751#M3621" target="_blank" rel="noopener"&gt;https://community.qlik.com/t5/Qlik-Design-Blog/Visualizing-comorbidity-Set-analysis-element-function-P/bc-p/1468751#M3621&lt;/A&gt;&lt;/P&gt;</description>
      <pubDate>Tue, 28 Jun 2022 08:34:18 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Member-Articles/Field-selections-AND-mode-for-Market-Basket-Analysis/ta-p/1484761</guid>
      <dc:creator>RadovanOresky</dc:creator>
      <dc:date>2022-06-28T08:34:18Z</dc:date>
    </item>
    <item>
      <title>Re: Field selections AND-mode for Market Basket Analysis</title>
      <link>https://community.qlik.com/t5/Member-Articles/Field-selections-AND-mode-for-Market-Basket-Analysis/tac-p/1484762#M307</link>
      <description>&lt;HTML&gt;&lt;HEAD&gt;&lt;/HEAD&gt;&lt;BODY&gt;&lt;P&gt;Great example.&amp;nbsp; Very helpful.&amp;nbsp; Very interested in other ways of performing Scenario or What-If Analysis.&lt;/P&gt;&lt;/BODY&gt;&lt;/HTML&gt;</description>
      <pubDate>Wed, 06 Jun 2018 06:14:11 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Member-Articles/Field-selections-AND-mode-for-Market-Basket-Analysis/tac-p/1484762#M307</guid>
      <dc:creator>vnelsoncrunch</dc:creator>
      <dc:date>2018-06-06T06:14:11Z</dc:date>
    </item>
    <item>
      <title>Re: Field selections AND-mode for Market Basket Analysis</title>
      <link>https://community.qlik.com/t5/Member-Articles/Field-selections-AND-mode-for-Market-Basket-Analysis/tac-p/2157132#M2133</link>
      <description>&lt;P&gt;Very very very usefull!!! Thank you!&lt;/P&gt;</description>
      <pubDate>Sun, 31 Dec 2023 13:43:08 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Member-Articles/Field-selections-AND-mode-for-Market-Basket-Analysis/tac-p/2157132#M2133</guid>
      <dc:creator>lftensini</dc:creator>
      <dc:date>2023-12-31T13:43:08Z</dc:date>
    </item>
  </channel>
</rss>

