<?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 Re: Displaying 'length' of answers from a calculation in CMS Development</title>
    <link>https://community.hubspot.com/t5/CMS-Development/Displaying-length-of-answers-from-a-calculation/m-p/452742#M23837</link>
    <description>&lt;P&gt;Hey &lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/60000"&gt;@ben-duchy&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Don't know if this is your whole code so correct me if I'm wrong - but do you have the calculations inside the same for loop as where you're using {{ total_weeks }}? Because if not it's not going to be able to associate the {{ total_weeks }} with the calculations. This worked for me :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;{% set table = hubdb_table_rows(XXXXXX) %}

{% for row in table %}
  {% set exchanged = unixtimestamp(row.exchange_date) %}
  {% set reservation = unixtimestamp(row.reservation_date) %}
  {% set exchanged_date = (reservation - exchanged)//24//60//60//1000 %}
  {% set total_weeks = (exchanged_date / 7 ) | round %}
    
  Answer = {{ total_weeks }}
{% endfor %}&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Tue, 29 Jun 2021 16:05:49 GMT</pubDate>
    <dc:creator>alyssamwilie</dc:creator>
    <dc:date>2021-06-29T16:05:49Z</dc:date>
    <item>
      <title>Displaying 'length' of answers from a calculation</title>
      <link>https://community.hubspot.com/t5/CMS-Development/Displaying-length-of-answers-from-a-calculation/m-p/452687#M23833</link>
      <description>&lt;P&gt;I've created a table that pulls in HubDB data between 2 date columns;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;{% set exchanged = unixtimestamp(row.exchange_date) %}&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;{% set reservation = unixtimestamp(row.reservation_date) %}&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;{% set exchanged_date = (exchanged - reservation)//24//60//60//1000 %}&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Above calculates the number of days between the 2 column entries.&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;&lt;STRONG&gt;{% set total_weeks = (exchanged_date / 7 ) | round %}&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;Then I use the number of days and round off to show how many weeks...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;{% for row in table %&lt;/STRONG&gt;}&lt;/P&gt;&lt;P&gt;Answer =&amp;nbsp;&lt;STRONG&gt;{{ total_weeks }}&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;{% endfor %}&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The above works, but now I want to display a bar graph that shows how many show 4 weeks, 5 weeks, 6 weeks etc. How do I calculate this? I tried the below but it didn't work:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;{% set test1 = (total_weeks, "equalto", "4") | length %}&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any ideas would be appreciated&lt;/P&gt;</description>
      <pubDate>Tue, 29 Jun 2021 15:20:04 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/Displaying-length-of-answers-from-a-calculation/m-p/452687#M23833</guid>
      <dc:creator>ben-duchy</dc:creator>
      <dc:date>2021-06-29T15:20:04Z</dc:date>
    </item>
    <item>
      <title>Re: Displaying 'length' of answers from a calculation</title>
      <link>https://community.hubspot.com/t5/CMS-Development/Displaying-length-of-answers-from-a-calculation/m-p/452742#M23837</link>
      <description>&lt;P&gt;Hey &lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/60000"&gt;@ben-duchy&lt;/a&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Don't know if this is your whole code so correct me if I'm wrong - but do you have the calculations inside the same for loop as where you're using {{ total_weeks }}? Because if not it's not going to be able to associate the {{ total_weeks }} with the calculations. This worked for me :&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;{% set table = hubdb_table_rows(XXXXXX) %}

{% for row in table %}
  {% set exchanged = unixtimestamp(row.exchange_date) %}
  {% set reservation = unixtimestamp(row.reservation_date) %}
  {% set exchanged_date = (reservation - exchanged)//24//60//60//1000 %}
  {% set total_weeks = (exchanged_date / 7 ) | round %}
    
  Answer = {{ total_weeks }}
{% endfor %}&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 29 Jun 2021 16:05:49 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/Displaying-length-of-answers-from-a-calculation/m-p/452742#M23837</guid>
      <dc:creator>alyssamwilie</dc:creator>
      <dc:date>2021-06-29T16:05:49Z</dc:date>
    </item>
    <item>
      <title>Re: Displaying 'length' of answers from a calculation</title>
      <link>https://community.hubspot.com/t5/CMS-Development/Displaying-length-of-answers-from-a-calculation/m-p/453070#M23857</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/91608"&gt;@alyssamwilie&lt;/a&gt;,&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Good spot! You're correct that the loop does need to cover everything as you stated. This works if you want to display all the information inside a table (see below), but what I now need to do is calculate how may rows show 01 wks or 02 wks etc, another words...&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;UL&gt;&lt;LI&gt;01 wks = 1&lt;/LI&gt;&lt;LI&gt;03 wks = 1&lt;/LI&gt;&lt;LI&gt;04 wks = 5&lt;/LI&gt;&lt;LI&gt;05 wks = 2&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-center" image-alt="table.jpg" style="width: 774px;"&gt;&lt;img src="https://community.hubspot.com/t5/image/serverpage/image-id/45435i2BD1F9E02958B9E9/image-size/large?v=v2&amp;amp;px=999" role="button" title="table.jpg" alt="table.jpg" /&gt;&lt;/span&gt;&lt;/P&gt;&lt;P&gt;If I was pulling data directly from HubDB, I would use the selectattr method for example:&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;{% set table = hubdb_table_rows(xxxxxxx, queryparam) %}&lt;/STRONG&gt;&lt;BR /&gt;&lt;STRONG&gt;{% set wks1 = table | selectattr ("weeks.name","equalto","one") | length %}&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;{% set wks2 = table | selectattr ("weeks.name","equalto","two") | length %}&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;STRONG&gt;{% set wks_total = (wks1 + wks2) %}&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;The 2 numbers then get added together within my page using&lt;STRONG&gt;&amp;nbsp;{{wks_total}}&lt;/STRONG&gt;&lt;/P&gt;&lt;P&gt;&lt;BR /&gt;Problem is that unlike my example above, the 'wks' column that I want to use doesn't exist in HubDB. The 'wks' column in the table above is a calculation between 2 HubDB columns, therefore how do I split a hubl calculation into more filtered data?&lt;/P&gt;</description>
      <pubDate>Wed, 30 Jun 2021 09:09:53 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/Displaying-length-of-answers-from-a-calculation/m-p/453070#M23857</guid>
      <dc:creator>ben-duchy</dc:creator>
      <dc:date>2021-06-30T09:09:53Z</dc:date>
    </item>
    <item>
      <title>Re: Displaying 'length' of answers from a calculation</title>
      <link>https://community.hubspot.com/t5/CMS-Development/Displaying-length-of-answers-from-a-calculation/m-p/453301#M23867</link>
      <description>&lt;P&gt;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/60000"&gt;@ben-duchy&lt;/a&gt; You would want to push the calculated weeks into an array and then use selectattr.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;{% set table = hubdb_table_rows(3958688) %}
    
{% set array = [] %} // create array variable

{% for row in table %}
  {% set exchanged = unixtimestamp(row.exchange_date) %}
  {% set reservation = unixtimestamp(row.reservation_date) %}
  {% set exchanged_date = (exchanged - reservation)//24//60//60//1000 %}

  {% set total_weeks = (exchanged_date / 7 ) | round %}

  {% do array.append({"weeks": total_weeks}) %} // append number of weeks to array
{% endfor %}

{% set wks1 = array|selectattr("weeks","equalto","1")|length %} // find length with selectattr
{{ wks1 }}&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And if you don't wanna write a whole bunch of sets for every possible number of weeks you could write a for loop with a range&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;{% for x in range(0,6) %}
  {% set wks = array|selectattr("weeks","equalto",x)|length %}
  {{ wks }}
{% endfor %}&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;And for the addition&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;{% set wks_total = {"total": "0"} %}

{% for x in range(-6,0) %}
  {% set wks = array|selectattr("weeks","equalto",x)|length %}

  {% set new_total = wks_total.total|int + wks|int %}
  {% do wks_total.update({"total": new_total}) %}
{% endfor %}
    
{{ wks_total.total }}&lt;/LI-CODE&gt;</description>
      <pubDate>Wed, 30 Jun 2021 14:47:53 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/Displaying-length-of-answers-from-a-calculation/m-p/453301#M23867</guid>
      <dc:creator>alyssamwilie</dc:creator>
      <dc:date>2021-06-30T14:47:53Z</dc:date>
    </item>
    <item>
      <title>Re: Displaying 'length' of answers from a calculation</title>
      <link>https://community.hubspot.com/t5/CMS-Development/Displaying-length-of-answers-from-a-calculation/m-p/453378#M23872</link>
      <description>&lt;P&gt;&amp;nbsp;Hi &lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/91608"&gt;@alyssamwilie&lt;/a&gt;, you're an absolute diamond! Thank you so much&amp;nbsp;&lt;span class="lia-unicode-emoji" title=":beaming_face_with_smiling_eyes:"&gt;😁&lt;/span&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 30 Jun 2021 16:07:27 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/CMS-Development/Displaying-length-of-answers-from-a-calculation/m-p/453378#M23872</guid>
      <dc:creator>ben-duchy</dc:creator>
      <dc:date>2021-06-30T16:07:27Z</dc:date>
    </item>
  </channel>
</rss>

