<?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 Expand a single row into multiple rows based on a specific field value? in App Development</title>
    <link>https://community.qlik.com/t5/App-Development/Expand-a-single-row-into-multiple-rows-based-on-a-specific-field/m-p/2487160#M101474</link>
    <description>&lt;P&gt;Let's say:&lt;BR /&gt;- I have a table with rows containing 'EU-27' in a field 'country'&lt;BR /&gt;- I need to create separate rows for each of the 27 EU countries &lt;BR /&gt;- The result should be 27 individual country rows for each original 'EU-27' row&lt;/P&gt;
&lt;P&gt;Here is my solution using a simple example, but I am wondering if there is a better approach to do it given that it is a common data prep task:&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;// Create a sample dataset using inline data
MainTable:
LOAD * INLINE [
country, value
UK, 1
France, 2
USA, 8
];

// Create a mapping table for UK countries
UKCountries:
LOAD * INLINE [
uk_nations
Wales
England
Northern Ireland
Scotland
];

// Now, create the final table with duplicated UK rows
FinalTable:
NoConcatenate
LOAD
country,
value
RESIDENT MainTable
WHERE country &amp;lt;&amp;gt; 'UK'
;

for each vCountry in FieldValueList('uk_nations')

CONCATENATE (FinalTable)
LOAD
'$(vCountry)' as country,
value
RESIDENT MainTable
WHERE country = 'UK'
;

next vCountry

drop table MainTable;&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 15 Oct 2024 18:18:34 GMT</pubDate>
    <dc:creator>prayner</dc:creator>
    <dc:date>2024-10-15T18:18:34Z</dc:date>
    <item>
      <title>Expand a single row into multiple rows based on a specific field value?</title>
      <link>https://community.qlik.com/t5/App-Development/Expand-a-single-row-into-multiple-rows-based-on-a-specific-field/m-p/2487160#M101474</link>
      <description>&lt;P&gt;Let's say:&lt;BR /&gt;- I have a table with rows containing 'EU-27' in a field 'country'&lt;BR /&gt;- I need to create separate rows for each of the 27 EU countries &lt;BR /&gt;- The result should be 27 individual country rows for each original 'EU-27' row&lt;/P&gt;
&lt;P&gt;Here is my solution using a simple example, but I am wondering if there is a better approach to do it given that it is a common data prep task:&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;// Create a sample dataset using inline data
MainTable:
LOAD * INLINE [
country, value
UK, 1
France, 2
USA, 8
];

// Create a mapping table for UK countries
UKCountries:
LOAD * INLINE [
uk_nations
Wales
England
Northern Ireland
Scotland
];

// Now, create the final table with duplicated UK rows
FinalTable:
NoConcatenate
LOAD
country,
value
RESIDENT MainTable
WHERE country &amp;lt;&amp;gt; 'UK'
;

for each vCountry in FieldValueList('uk_nations')

CONCATENATE (FinalTable)
LOAD
'$(vCountry)' as country,
value
RESIDENT MainTable
WHERE country = 'UK'
;

next vCountry

drop table MainTable;&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Oct 2024 18:18:34 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Expand-a-single-row-into-multiple-rows-based-on-a-specific-field/m-p/2487160#M101474</guid>
      <dc:creator>prayner</dc:creator>
      <dc:date>2024-10-15T18:18:34Z</dc:date>
    </item>
    <item>
      <title>Re: Expand a single row into multiple rows based on a specific field value?</title>
      <link>https://community.qlik.com/t5/App-Development/Expand-a-single-row-into-multiple-rows-based-on-a-specific-field/m-p/2487166#M101475</link>
      <description>&lt;P&gt;&lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/220099"&gt;@prayner&lt;/a&gt;&amp;nbsp; you can do this using simple join instead of running loop&lt;/P&gt;
&lt;P&gt;MainTable:&lt;BR /&gt;LOAD * INLINE [&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;country&lt;/STRONG&gt;&lt;/FONT&gt;, value&lt;BR /&gt;UK, 1&lt;BR /&gt;France, 2&lt;BR /&gt;USA, 8&lt;BR /&gt;];&lt;/P&gt;
&lt;P&gt;Left Join(MainTable)&lt;BR /&gt;// Create a mapping table for UK countries&lt;BR /&gt;LOAD * INLINE [&lt;BR /&gt;&lt;FONT color="#FF0000"&gt;&lt;STRONG&gt;country&lt;/STRONG&gt;&lt;/FONT&gt;,uk_nations&lt;BR /&gt;UK,Wales&lt;BR /&gt;UK,England&lt;BR /&gt;UK,Northern Ireland&lt;BR /&gt;UK,Scotland&lt;BR /&gt;];&lt;/P&gt;
&lt;P&gt;Final:&lt;BR /&gt;Load *,&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;if(len(trim(uk_nations))=0,country,uk_nations) as Country_final&lt;BR /&gt;Resident MainTable;&lt;/P&gt;
&lt;P&gt;Drop Table MainTable;&lt;/P&gt;
&lt;P&gt;Drop Fields country,uk_nations;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="Kushal_Chawda_0-1729019545902.png" style="width: 400px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/172967i20F5EB60B072BFD6/image-size/medium?v=v2&amp;amp;px=400" role="button" title="Kushal_Chawda_0-1729019545902.png" alt="Kushal_Chawda_0-1729019545902.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 15 Oct 2024 19:12:45 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Expand-a-single-row-into-multiple-rows-based-on-a-specific-field/m-p/2487166#M101475</guid>
      <dc:creator>Kushal_Chawda</dc:creator>
      <dc:date>2024-10-15T19:12:45Z</dc:date>
    </item>
    <item>
      <title>Re: Expand a single row into multiple rows based on a specific field value?</title>
      <link>https://community.qlik.com/t5/App-Development/Expand-a-single-row-into-multiple-rows-based-on-a-specific-field/m-p/2487197#M101486</link>
      <description>&lt;P&gt;Kudos nice solution!!&lt;/P&gt;</description>
      <pubDate>Tue, 15 Oct 2024 23:34:21 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Expand-a-single-row-into-multiple-rows-based-on-a-specific-field/m-p/2487197#M101486</guid>
      <dc:creator>seanbruton</dc:creator>
      <dc:date>2024-10-15T23:34:21Z</dc:date>
    </item>
    <item>
      <title>Re: Expand a single row into multiple rows based on a specific field value?</title>
      <link>https://community.qlik.com/t5/App-Development/Expand-a-single-row-into-multiple-rows-based-on-a-specific-field/m-p/2487283#M101500</link>
      <description>&lt;P&gt;Nice solution and thanks for sharing, Kushal&lt;/P&gt;</description>
      <pubDate>Wed, 16 Oct 2024 07:16:48 GMT</pubDate>
      <guid>https://community.qlik.com/t5/App-Development/Expand-a-single-row-into-multiple-rows-based-on-a-specific-field/m-p/2487283#M101500</guid>
      <dc:creator>prayner</dc:creator>
      <dc:date>2024-10-16T07:16:48Z</dc:date>
    </item>
  </channel>
</rss>

