<?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 Dynamic sum of all column in FlexSim Forum</title>
    <link>https://forums.autodesk.com/t5/flexsim-forum/dynamic-sum-of-all-column/m-p/13568234#M69212</link>
    <description>&lt;P&gt;&lt;I&gt;[ FlexSim 18.2.0 ]&lt;/I&gt;&lt;/P&gt;&lt;P&gt;Hello !&lt;/P&gt;
&lt;P&gt;I have a Global Table that gets more and more column during the simulation according to the number of product and with several rows. From this table I want the sum of all rows for each column. I tried SUM(*), which would be perfect but it does not work. Is there any way to achieve the same with one SQL-Request ? Is there any way to use INFORMATION_SCHEMA in Flexsim ?&lt;/P&gt;
&lt;P&gt;Best regards&lt;/P&gt;</description>
    <pubDate>Fri, 16 Nov 2018 08:50:24 GMT</pubDate>
    <dc:creator>sebastien_b49</dc:creator>
    <dc:date>2018-11-16T08:50:24Z</dc:date>
    <item>
      <title>Dynamic sum of all column</title>
      <link>https://forums.autodesk.com/t5/flexsim-forum/dynamic-sum-of-all-column/m-p/13568234#M69212</link>
      <description>&lt;P&gt;&lt;I&gt;[ FlexSim 18.2.0 ]&lt;/I&gt;&lt;/P&gt;&lt;P&gt;Hello !&lt;/P&gt;
&lt;P&gt;I have a Global Table that gets more and more column during the simulation according to the number of product and with several rows. From this table I want the sum of all rows for each column. I tried SUM(*), which would be perfect but it does not work. Is there any way to achieve the same with one SQL-Request ? Is there any way to use INFORMATION_SCHEMA in Flexsim ?&lt;/P&gt;
&lt;P&gt;Best regards&lt;/P&gt;</description>
      <pubDate>Fri, 16 Nov 2018 08:50:24 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/flexsim-forum/dynamic-sum-of-all-column/m-p/13568234#M69212</guid>
      <dc:creator>sebastien_b49</dc:creator>
      <dc:date>2018-11-16T08:50:24Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic sum of all column</title>
      <link>https://forums.autodesk.com/t5/flexsim-forum/dynamic-sum-of-all-column/m-p/13568235#M69213</link>
      <description>&lt;P&gt;Hi, &lt;/P&gt;&lt;P&gt;could you please share an example, why SUM does not work?&lt;/P&gt;</description>
      <pubDate>Fri, 16 Nov 2018 09:34:37 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/flexsim-forum/dynamic-sum-of-all-column/m-p/13568235#M69213</guid>
      <dc:creator>sebastian_hemmannE3JAU</dc:creator>
      <dc:date>2018-11-16T09:34:37Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic sum of all column</title>
      <link>https://forums.autodesk.com/t5/flexsim-forum/dynamic-sum-of-all-column/m-p/13568236#M69214</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;SUM works only if I use it with a specific column, like SUM(Total). So to have the sum of all column I would need to do SUM(Total), SUM(Col2), SUM(Col3),...yet I do not know how many column I will have during the simulation. the concept of SUM(*) would work but this is not a proper request syntax.&lt;/P&gt;
&lt;P&gt;For instance at the beginning of the simulation I have the following global table.&lt;/P&gt;
&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;/TD&gt;&lt;TD&gt;Total&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Factory 1&lt;BR /&gt;&lt;/TD&gt;&lt;TD&gt;&lt;BR /&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Factory 2&lt;BR /&gt;&lt;/TD&gt;&lt;TD&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;
&lt;P&gt;Then during the simulation the model updates dynamically the Global Table when one Sink receive a new Product. So athe end of the simulation I could have had 4 products which would make my Table look like that&lt;/P&gt;
&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;BR /&gt;&lt;/TD&gt;&lt;TD&gt;Total&lt;BR /&gt;&lt;/TD&gt;&lt;TD&gt;Prod 1&lt;/TD&gt;&lt;TD&gt;Prod 2&lt;/TD&gt;&lt;TD&gt;Prod 3&lt;/TD&gt;&lt;TD&gt;Prod 4&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Factory 1&lt;BR /&gt;&lt;/TD&gt;&lt;TD&gt;14&lt;/TD&gt;&lt;TD&gt;2&lt;/TD&gt;&lt;TD&gt;3&lt;/TD&gt;&lt;TD&gt;4&lt;/TD&gt;&lt;TD&gt;5&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Factory 2&lt;BR /&gt;&lt;/TD&gt;&lt;TD&gt;30&lt;/TD&gt;&lt;TD&gt;6&lt;/TD&gt;&lt;TD&gt;7&lt;/TD&gt;&lt;TD&gt;8&lt;/TD&gt;&lt;TD&gt;9&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;
&lt;P&gt;And from this table I would like to sum on each column with a calculated table as follows. But I haven't succeed in doing that. I would love to have a SQL Request being able to do that without haveing to change the whole modell and how data are collected.&lt;/P&gt;
&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;&lt;/TD&gt;&lt;TD&gt;SUM(Total)&lt;/TD&gt;&lt;TD&gt;SUM(Prod 1)&lt;/TD&gt;&lt;TD&gt;SUM(Prod 2)&lt;/TD&gt;&lt;TD&gt;SUM(Prod 3)&lt;/TD&gt;&lt;TD&gt;SUM(Prod 4)&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Sum&lt;BR /&gt;&lt;/TD&gt;&lt;TD&gt;14&lt;/TD&gt;&lt;TD&gt;8&lt;/TD&gt;&lt;TD&gt;10&lt;BR /&gt;&lt;/TD&gt;&lt;TD&gt;12&lt;BR /&gt;&lt;/TD&gt;&lt;TD&gt;14&lt;BR /&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;&lt;BR /&gt;&lt;/TD&gt;&lt;TD&gt;&lt;BR /&gt;&lt;/TD&gt;&lt;TD&gt;&lt;BR /&gt;&lt;/TD&gt;&lt;TD&gt;&lt;BR /&gt;&lt;/TD&gt;&lt;TD&gt;&lt;BR /&gt;&lt;/TD&gt;&lt;TD&gt;&lt;BR /&gt;&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;</description>
      <pubDate>Fri, 16 Nov 2018 10:01:43 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/flexsim-forum/dynamic-sum-of-all-column/m-p/13568236#M69214</guid>
      <dc:creator>sebastien_b49</dc:creator>
      <dc:date>2018-11-16T10:01:43Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic sum of all column</title>
      <link>https://forums.autodesk.com/t5/flexsim-forum/dynamic-sum-of-all-column/m-p/13568237#M69215</link>
      <description>&lt;P&gt;&lt;A rel="user" href="https://answers.flexsim.com/users/7518/sebastienb2.html" nodeid="7518"&gt;@Sébastien B2&lt;/A&gt; Isn't it easier if you execute the query everytime something comes into the sink? You then know what column to recalculate and you can create the SUM table on the fly.&lt;/P&gt;</description>
      <pubDate>Fri, 16 Nov 2018 15:42:12 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/flexsim-forum/dynamic-sum-of-all-column/m-p/13568237#M69215</guid>
      <dc:creator>SCHamoen</dc:creator>
      <dc:date>2018-11-16T15:42:12Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic sum of all column</title>
      <link>https://forums.autodesk.com/t5/flexsim-forum/dynamic-sum-of-all-column/m-p/13568238#M69216</link>
      <description>&lt;P&gt;I would recommend a different schema for your table. If you use a schema like the following:&lt;/P&gt;&lt;TABLE&gt;&lt;TBODY&gt;&lt;TR&gt;&lt;TD&gt;Factory&lt;/TD&gt;&lt;TD&gt;Product&lt;/TD&gt;&lt;TD&gt;Quantity&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Factory1&lt;/TD&gt;&lt;TD&gt;Prod1&lt;/TD&gt;&lt;TD&gt;12&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Factory1&lt;/TD&gt;&lt;TD&gt;Prod2&lt;/TD&gt;&lt;TD&gt;14&lt;/TD&gt;&lt;/TR&gt;&lt;TR&gt;&lt;TD&gt;Factory2&lt;/TD&gt;&lt;TD&gt;Prod1&lt;/TD&gt;&lt;TD&gt;18&lt;/TD&gt;&lt;/TR&gt;&lt;/TBODY&gt;&lt;/TABLE&gt;&lt;P&gt;Then you can write many helpful queries. If you want to sum all products in all factories, you can use&lt;/P&gt;&lt;PRE&gt;SELECT SUM(Quantity) AS Total FROM MyTable&lt;/PRE&gt;&lt;P&gt;If you want the total per product, you can use&lt;/P&gt;&lt;PRE&gt;SELECT Product, SUM(Quantity) AS Total FROM MyTable GROUP BY Product&lt;/PRE&gt;&lt;P&gt;Or if you want the total per factory, you can use&lt;/P&gt;&lt;PRE&gt;SELECT Factory, SUM(Quantity) AS Total FROM MyTable GROUP BY Factory&lt;/PRE&gt;&lt;P&gt;If you choose to keep the same schema, there is no SQL query that will work for every model run. You could use FlexScript to run an analysis on the table:&lt;/P&gt;&lt;PRE&gt;Table myTable = Table("MyTable");
for (int r = 1; r &amp;lt;= myTable.numRows; r++) {
	int total = 0;
	for (int c = 1; c &amp;lt;= myTable.numCols; c++) {
		string header = myTable.getColHeader(c);
		if (header == "Total")
			continue;
		
		total += myTable&lt;R&gt;&lt;C&gt;;
	}
	myTable&lt;R&gt;["Total"] = total;
}&lt;/R&gt;&lt;/C&gt;&lt;/R&gt;&lt;/PRE&gt;</description>
      <pubDate>Fri, 16 Nov 2018 19:05:00 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/flexsim-forum/dynamic-sum-of-all-column/m-p/13568238#M69216</guid>
      <dc:creator>JordanLJohnson</dc:creator>
      <dc:date>2018-11-16T19:05:00Z</dc:date>
    </item>
    <item>
      <title>Re: Dynamic sum of all column</title>
      <link>https://forums.autodesk.com/t5/flexsim-forum/dynamic-sum-of-all-column/m-p/13568239#M69217</link>
      <description>&lt;P&gt;Hello Jordan.&lt;/P&gt;
&lt;P&gt;Thank you for your detailed answer. I was already thinking about changing the tables like you mentionned. But I would have had to change a lot of things in the model and because of that I wanted to know if there was another solution.&lt;/P&gt;
&lt;P&gt;I could use a Flexscript solution although the one with a new Table arrangement would be more useful. I think I'll change the whole model as far as data collection is concerned. It also may be better for a later addition of functionnalities.&lt;/P&gt;
&lt;P&gt;Thank you again for your help !&lt;/P&gt;</description>
      <pubDate>Mon, 19 Nov 2018 10:59:13 GMT</pubDate>
      <guid>https://forums.autodesk.com/t5/flexsim-forum/dynamic-sum-of-all-column/m-p/13568239#M69217</guid>
      <dc:creator>sebastien_b49</dc:creator>
      <dc:date>2018-11-19T10:59:13Z</dc:date>
    </item>
  </channel>
</rss>

