I currently have 2 conditions that pulls information from HubDB which displays the amount of a particlar item:
{% set num_reserved = table | selectattr (“plot_status.name”,“equalto”,“Reserved”) | length %}
{% set num_detached = table | selectattr (“house_type.name”,“equalto”,“Detached”) | length %}
Total Reserved: {{ num_reserved }} <!--(eg displays 15) -->
Total Detached: {{ num_detached }} <!--(eg displays 5) -->
Is there a way to add these filters together for example show the number of plots that are Reserved AND Detached:
Total of Detached houses that are also Reserved: {{ ? }} <!--(eg displays 2) -->
@ben-duchy
The last two lines confude me.
Is there a way to add these filters together for example show the number of plots that are Reserved AND Detached:
This looks like you want to add the two together, so you would have 15 + 5 = 20.
To get that, you could create a third variable and add the others.
{% set totes = num_reserved + num_detached %}
{{ totes }}
But the last line seems like you are expecting 2 returned unless you inadvertently left out a 0
@piersg what do you think?
piersg
March 22, 2021, 2:27pm
3
@dennisedson I believe @ben-duchy wants to show properties that are both reserved and detached.
You could do this:
{% for row in hubdb_table_rows([TABLE ID], "plot_status=Reserved&house_type=Detached") %}
{{row}}
{% endfor %}
Hi @dennisedson ,
My apologies for the confusion. I simply wanted to filter out how many rows met both conditions, for example out of the 5 detached properties, 3 are sold. I wanted to see how many are reserved, but at the same time I don’t want to include any other house types that are reserved.
Using 2 “| selectattr”, I was able to combine the conditions into 1 and therefore calulate how many properties met both criterias:
{% set total_reserved_and_detached = table | selectattr (“plot_status.name”,“equalto”,“Reserved”) | selectattr (“house_type.name”,“equalto”,“Detached”) | length %}
{{ total_reserved_and_detached }} <!-- answer gave me 2 -->