Displaying 'length' of answers from a calculation

@ben-duchy You would want to push the calculated weeks into an array and then use selectattr.

{% 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 }}

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

{% for x in range(0,6) %}
 {% set wks = array|selectattr("weeks","equalto",x)|length %}
 {{ wks }}
{% endfor %}

And for the addition

{% 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 }}