<?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 loop and concatintion in Management &amp; Governance</title>
    <link>https://community.qlik.com/t5/Management-Governance/loop-and-concatintion/m-p/2089485#M25236</link>
    <description>&lt;P&gt;In honor of the dear Click Sense developers&lt;BR /&gt;I have tables of goals for 2018 and 2019 in the model, which I chained, but I want to create a situation where every new goal file that arrives in a folder on the computer will be automatically chained to the model. That is, I have to create a loop and connection of all the data in an orderly manner.&lt;/P&gt;
&lt;P&gt;I want to generate the script so that it is generic. that if a file from the year 2020 / 2021 is added for example to the folder - he will upload it to me as well.&lt;BR /&gt;I need to use a loop that will extract the year from the name of the file into a variable and use the variable to extract the appropriate tab from Excel.&lt;/P&gt;
&lt;P&gt;How do I write the script?&lt;/P&gt;</description>
    <pubDate>Fri, 30 Jun 2023 10:39:23 GMT</pubDate>
    <dc:creator>somthingmendi123</dc:creator>
    <dc:date>2023-06-30T10:39:23Z</dc:date>
    <item>
      <title>loop and concatintion</title>
      <link>https://community.qlik.com/t5/Management-Governance/loop-and-concatintion/m-p/2089485#M25236</link>
      <description>&lt;P&gt;In honor of the dear Click Sense developers&lt;BR /&gt;I have tables of goals for 2018 and 2019 in the model, which I chained, but I want to create a situation where every new goal file that arrives in a folder on the computer will be automatically chained to the model. That is, I have to create a loop and connection of all the data in an orderly manner.&lt;/P&gt;
&lt;P&gt;I want to generate the script so that it is generic. that if a file from the year 2020 / 2021 is added for example to the folder - he will upload it to me as well.&lt;BR /&gt;I need to use a loop that will extract the year from the name of the file into a variable and use the variable to extract the appropriate tab from Excel.&lt;/P&gt;
&lt;P&gt;How do I write the script?&lt;/P&gt;</description>
      <pubDate>Fri, 30 Jun 2023 10:39:23 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Management-Governance/loop-and-concatintion/m-p/2089485#M25236</guid>
      <dc:creator>somthingmendi123</dc:creator>
      <dc:date>2023-06-30T10:39:23Z</dc:date>
    </item>
    <item>
      <title>Re: loop and concatintion</title>
      <link>https://community.qlik.com/t5/Management-Governance/loop-and-concatintion/m-p/2089755#M25239</link>
      <description>&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;import os
import openpyxl

def extract_year(filename):
  year = filename[-4:]
  return int(year)

def get_tab(excel_file, year):
  sheet_name = f"{year} Goals"
  return excel_file[sheet_name]

def main():
  # Get the folder where the goal files are stored
  folder_path = "C:\\Users\\your_username\\Desktop\\goals"

  # Get a list of all the files in the folder
  files = os.listdir(folder_path)

  # Create a loop to iterate through the files
  for file in files:
    # Extract the year from the file name
    year = extract_year(file)

    # Open the Excel file
    excel_file = openpyxl.load_workbook(f"{folder_path}/{file}")

    # Get the appropriate tab from the Excel file
    tab = get_tab(excel_file, year)

    # Chain the tab to the model
    tab.chain()

if __name__ == "__main__":
  main()
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 26 Apr 2024 17:59:45 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Management-Governance/loop-and-concatintion/m-p/2089755#M25239</guid>
      <dc:creator>biwek86619</dc:creator>
      <dc:date>2024-04-26T17:59:45Z</dc:date>
    </item>
  </channel>
</rss>

