We use cookies to make HubSpot's community a better place. Cookies help to provide a more personalized experience and relevant advertising for you, and web analytics for us. To learn more, and to see a full list of cookies we use, check out our Cookie Policy (baked goods not included).
Mar 19, 2021 6:25 AM - edited Mar 19, 2021 6:26 AM
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) -->
Solved! Go to Solution.
Mar 22, 2021 10:31 AM
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 --> 😊
Mar 22, 2021 10:31 AM
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 --> 😊
Mar 22, 2021 10:15 AM
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?
![]() | Make sure to subscribe to our YouTube channel where you can find the HubSpot Community Developer Show |
Mar 22, 2021 10:27 AM
@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 %}