{"id":170,"date":"2021-06-24T16:18:20","date_gmt":"2021-06-24T16:18:20","guid":{"rendered":"http:\/\/approbato.com\/blog\/?p=170"},"modified":"2022-08-04T18:57:46","modified_gmt":"2022-08-04T18:57:46","slug":"split-a-table-in-multiple-files-for-loop-qlik-script","status":"publish","type":"post","link":"https:\/\/approbato.com\/blog\/split-a-table-in-multiple-files-for-loop-qlik-script\/","title":{"rendered":"Split a table in multiple files (For loop) &#8211; Qlik Script"},"content":{"rendered":"\n<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<\/p>\n\n\n\n<p class=\"has-vivid-red-color has-text-color\">Hi! <strong>Please tell me what kind of Qlik content you think is relevant or interesting to have in the channel (use the link below). Thanks!<\/strong><\/p>\n\n\n\n<p>Link: <a href=\"https:\/\/approbato.com\/blog\/quick-qlik-survey\/\" target=\"_blank\" rel=\"noreferrer noopener\">https:\/\/approbato.com\/blog\/quick-qlik-survey\/<\/a><\/p>\n\n\n\n<p>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;<\/p>\n\n\n\n<p>When you need to create separate files from the same table using a filter, this is a good way to go:<\/p>\n\n\n\n<p>Let&#8217;s consider that we have a table with many countries in the Country column and you need to split this table creating one csv file for each country. <\/p>\n\n\n\n<p>If you are new to Qlik the first thing to know is that we can filter the table in the script using the <strong>where<\/strong> clause, and also export the table using the <strong>Store<\/strong> command.<\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe loading=\"lazy\" title=\"For loop and variables in Qlik Sense Script - Split a table in multiple files\" width=\"640\" height=\"360\" src=\"https:\/\/www.youtube.com\/embed\/LSTNgmGX5lw?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture\" allowfullscreen><\/iframe>\n<\/div><\/figure>\n\n\n\n<p>In the video above you will see the steps to export multiple tables using the following script as base:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ Creating a list of Countries without duplicate records\nCountries:\nLOAD distinct\n    Area\nFROM &#91;lib:\/\/Source\/FAOSTAT_data_6-23-2021.xls]\n(biff, embedded labels, table is Sheet1$);\n\n\n\/\/ If you want to export the table above, uncomment the store command below\n\/\/ Store Countries into &#91;lib:\/\/Source\/CountryList.csv] (txt,delimiter is ';');\n\n\n\/\/ Loop until the number of rows from the Countries table (-1) is reached\nFor i=0 to NoOfRows('Countries')-1\n\n\/\/ Create a variable to filter the table below\n\/\/ The peek functions considers: 1) Name of column  , 2) number of row , 3) Name of the table\nLet vCountry = peek('Area', i , 'Countries' ) ;\n\n\nMainTable:\nLOAD\n    \"Domain Code\",\n    Domain,\n    \"Area Code (FAO)\",\n    Area,\n    \"Element Code\",\n    Element,\n    \"Item Code (FAO)\",\n    Item,\n    \"Year Code\",\n    \"Year\",\n    Unit,\n    Value,\n    Flag,\n    \"Flag Description\"\nFROM &#91;lib:\/\/Source\/FAOSTAT_data_6-23-2021.xls]\n(biff, embedded labels, table is Sheet1$)\nwhere Area='$(vCountry)';\n\n\nStore MainTable into &#91;lib:\/\/Source\/$(vCountry).csv] (txt, delimiter is ';');\n\/\/Drop the table otherwise the last file exported will contain records from all the other countries (they pill up)\nDrop table MainTable;\n\n\/\/ Next i to make the loop work\nNext i<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>How to split a database using a Where clause with For loop.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[14,5,2,15],"tags":[17,16],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v20.2.1 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>Split a table in multiple files (For loop) - Qlik Script - Guilherme Approbato<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/approbato.com\/blog\/split-a-table-in-multiple-files-for-loop-qlik-script\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Split a table in multiple files (For loop) - Qlik Script - Guilherme Approbato\" \/>\n<meta property=\"og:description\" content=\"How to split a database using a Where clause with For loop.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/approbato.com\/blog\/split-a-table-in-multiple-files-for-loop-qlik-script\/\" \/>\n<meta property=\"og:site_name\" content=\"Guilherme Approbato\" \/>\n<meta property=\"article:published_time\" content=\"2021-06-24T16:18:20+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2022-08-04T18:57:46+00:00\" \/>\n<meta name=\"author\" content=\"Guilherme Approbato\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Guilherme Approbato\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/approbato.com\/blog\/split-a-table-in-multiple-files-for-loop-qlik-script\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/approbato.com\/blog\/split-a-table-in-multiple-files-for-loop-qlik-script\/\"},\"author\":{\"name\":\"Guilherme Approbato\",\"@id\":\"https:\/\/approbato.com\/blog\/#\/schema\/person\/64f139096656d0884d037457309f9c75\"},\"headline\":\"Split a table in multiple files (For loop) &#8211; Qlik Script\",\"datePublished\":\"2021-06-24T16:18:20+00:00\",\"dateModified\":\"2022-08-04T18:57:46+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/approbato.com\/blog\/split-a-table-in-multiple-files-for-loop-qlik-script\/\"},\"wordCount\":151,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/approbato.com\/blog\/#\/schema\/person\/64f139096656d0884d037457309f9c75\"},\"keywords\":[\"For Loop\",\"Qlik Script\"],\"articleSection\":[\"English\",\"Exploring data\",\"Qlik\",\"Script\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/approbato.com\/blog\/split-a-table-in-multiple-files-for-loop-qlik-script\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/approbato.com\/blog\/split-a-table-in-multiple-files-for-loop-qlik-script\/\",\"url\":\"https:\/\/approbato.com\/blog\/split-a-table-in-multiple-files-for-loop-qlik-script\/\",\"name\":\"Split a table in multiple files (For loop) - Qlik Script - Guilherme Approbato\",\"isPartOf\":{\"@id\":\"https:\/\/approbato.com\/blog\/#website\"},\"datePublished\":\"2021-06-24T16:18:20+00:00\",\"dateModified\":\"2022-08-04T18:57:46+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/approbato.com\/blog\/split-a-table-in-multiple-files-for-loop-qlik-script\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/approbato.com\/blog\/split-a-table-in-multiple-files-for-loop-qlik-script\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/approbato.com\/blog\/split-a-table-in-multiple-files-for-loop-qlik-script\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/approbato.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Split a table in multiple files (For loop) &#8211; Qlik Script\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/approbato.com\/blog\/#website\",\"url\":\"https:\/\/approbato.com\/blog\/\",\"name\":\"Guilherme Approbato\",\"description\":\"Management Consulting | Certified Qlik Data Architect and Business Analyst\",\"publisher\":{\"@id\":\"https:\/\/approbato.com\/blog\/#\/schema\/person\/64f139096656d0884d037457309f9c75\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/approbato.com\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\/\/approbato.com\/blog\/#\/schema\/person\/64f139096656d0884d037457309f9c75\",\"name\":\"Guilherme Approbato\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/approbato.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"http:\/\/approbato.com\/blog\/wp-content\/uploads\/2020\/10\/guilherme-96x96.jpg\",\"contentUrl\":\"http:\/\/approbato.com\/blog\/wp-content\/uploads\/2020\/10\/guilherme-96x96.jpg\",\"caption\":\"Guilherme Approbato\"},\"logo\":{\"@id\":\"https:\/\/approbato.com\/blog\/#\/schema\/person\/image\/\"},\"sameAs\":[\"http:\/\/approbato.com\/blog\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Split a table in multiple files (For loop) - Qlik Script - Guilherme Approbato","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/approbato.com\/blog\/split-a-table-in-multiple-files-for-loop-qlik-script\/","og_locale":"en_US","og_type":"article","og_title":"Split a table in multiple files (For loop) - Qlik Script - Guilherme Approbato","og_description":"How to split a database using a Where clause with For loop.","og_url":"https:\/\/approbato.com\/blog\/split-a-table-in-multiple-files-for-loop-qlik-script\/","og_site_name":"Guilherme Approbato","article_published_time":"2021-06-24T16:18:20+00:00","article_modified_time":"2022-08-04T18:57:46+00:00","author":"Guilherme Approbato","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Guilherme Approbato","Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/approbato.com\/blog\/split-a-table-in-multiple-files-for-loop-qlik-script\/#article","isPartOf":{"@id":"https:\/\/approbato.com\/blog\/split-a-table-in-multiple-files-for-loop-qlik-script\/"},"author":{"name":"Guilherme Approbato","@id":"https:\/\/approbato.com\/blog\/#\/schema\/person\/64f139096656d0884d037457309f9c75"},"headline":"Split a table in multiple files (For loop) &#8211; Qlik Script","datePublished":"2021-06-24T16:18:20+00:00","dateModified":"2022-08-04T18:57:46+00:00","mainEntityOfPage":{"@id":"https:\/\/approbato.com\/blog\/split-a-table-in-multiple-files-for-loop-qlik-script\/"},"wordCount":151,"commentCount":0,"publisher":{"@id":"https:\/\/approbato.com\/blog\/#\/schema\/person\/64f139096656d0884d037457309f9c75"},"keywords":["For Loop","Qlik Script"],"articleSection":["English","Exploring data","Qlik","Script"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/approbato.com\/blog\/split-a-table-in-multiple-files-for-loop-qlik-script\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/approbato.com\/blog\/split-a-table-in-multiple-files-for-loop-qlik-script\/","url":"https:\/\/approbato.com\/blog\/split-a-table-in-multiple-files-for-loop-qlik-script\/","name":"Split a table in multiple files (For loop) - Qlik Script - Guilherme Approbato","isPartOf":{"@id":"https:\/\/approbato.com\/blog\/#website"},"datePublished":"2021-06-24T16:18:20+00:00","dateModified":"2022-08-04T18:57:46+00:00","breadcrumb":{"@id":"https:\/\/approbato.com\/blog\/split-a-table-in-multiple-files-for-loop-qlik-script\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/approbato.com\/blog\/split-a-table-in-multiple-files-for-loop-qlik-script\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/approbato.com\/blog\/split-a-table-in-multiple-files-for-loop-qlik-script\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/approbato.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Split a table in multiple files (For loop) &#8211; Qlik Script"}]},{"@type":"WebSite","@id":"https:\/\/approbato.com\/blog\/#website","url":"https:\/\/approbato.com\/blog\/","name":"Guilherme Approbato","description":"Management Consulting | Certified Qlik Data Architect and Business Analyst","publisher":{"@id":"https:\/\/approbato.com\/blog\/#\/schema\/person\/64f139096656d0884d037457309f9c75"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/approbato.com\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/approbato.com\/blog\/#\/schema\/person\/64f139096656d0884d037457309f9c75","name":"Guilherme Approbato","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/approbato.com\/blog\/#\/schema\/person\/image\/","url":"http:\/\/approbato.com\/blog\/wp-content\/uploads\/2020\/10\/guilherme-96x96.jpg","contentUrl":"http:\/\/approbato.com\/blog\/wp-content\/uploads\/2020\/10\/guilherme-96x96.jpg","caption":"Guilherme Approbato"},"logo":{"@id":"https:\/\/approbato.com\/blog\/#\/schema\/person\/image\/"},"sameAs":["http:\/\/approbato.com\/blog"]}]}},"_links":{"self":[{"href":"https:\/\/approbato.com\/blog\/wp-json\/wp\/v2\/posts\/170"}],"collection":[{"href":"https:\/\/approbato.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/approbato.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/approbato.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/approbato.com\/blog\/wp-json\/wp\/v2\/comments?post=170"}],"version-history":[{"count":4,"href":"https:\/\/approbato.com\/blog\/wp-json\/wp\/v2\/posts\/170\/revisions"}],"predecessor-version":[{"id":217,"href":"https:\/\/approbato.com\/blog\/wp-json\/wp\/v2\/posts\/170\/revisions\/217"}],"wp:attachment":[{"href":"https:\/\/approbato.com\/blog\/wp-json\/wp\/v2\/media?parent=170"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/approbato.com\/blog\/wp-json\/wp\/v2\/categories?post=170"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/approbato.com\/blog\/wp-json\/wp\/v2\/tags?post=170"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}