web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Customer experience | Sales, Customer Insights,...
Suggested Answer

count #each results

(0) ShareShare
ReportReport
Posted on by 386

Hi

do you know if you can count the results of a query in the marketing email ?

example below:

<p>You have purchased:</p> <ul>

<!-- {{#each contact.contact_product_productid}} -->

<li>{{this.name}}</li>

<!-- {{/each}} --> </ul>

some group by can have 3 results other 10 etc

do you know which function/method for "this" obj can be use to give you the results count ?

 

thank you

I have the same question (0)
  • Suggested answer
    Leah Ju Profile Picture
    Microsoft Employee on at

    Hi slx,

    Unfortunately, you can't count query results directly in marketing emails, there is no OOB function to do so currently.

    It is recommended to create a custom field that type is rollup in Contact entity, which records the count of products.

    pastedimage1667871876624v2.png

    Edit it as the following screenshot.

    pastedimage1667871792437v1.png

    Note: The default recurrence of the rollup calculation is 1 hour. You can change this with following steps:

    1. Navigating to Settings > System Jobs
    2. Select view "All Rollup Field Calculation Jobs"
    3. Select and Open the job with name "Calculate rollup fields for <your entity schema name> entity.
    4. In the job window, on the command bar, click Actions > Modify Recurrence.

    Then you can use the following code into the marketing email to show the number of related products:

    {{contact.new_countofproducts}}

    Result:

    pastedimage1667879089325v3.jpeg

  • slx Profile Picture
    386 on at

    Thank you, as this is javascript / html I though there is a way to count {{this.xxx}} results and add further personalization based on results (if 1 or more)

    I am new to marketing stuff but familiar with dynamics. I try to describe a strange limitation below:

    1) we build segments and apply the query block for a subset of data, let's say target only contacts for products with product type = xxx

    2) the segments contain contacts only (not all contacts but the contacts from 1)

    3) when segment is used in a customer journey and sending a marketing email for contacts, for the iteration [tag:each] it's not possible to get the subset of data it will list all associated records (not possible to get only products with type =xxx unless hardcoded in the email body js/html)

    4) the workaround found was to use an intermediary entity to keep the query block results and then use this in [tag:each] query but not sure if there is any solution out of the box

    kind regards

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Responsible AI policies

As AI tools become more common, we’re introducing a Responsible AI Use…

Congratulations to our 2025 Community Spotlights

Thanks to all of our 2025 Community Spotlight stars!

Leaderboard > Customer experience | Sales, Customer Insights, CRM

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 57 Super User 2026 Season 1

#1
Tom_Gioielli Profile Picture

Tom_Gioielli 57 Super User 2026 Season 1

#3
Eugen Podkorytov Profile Picture

Eugen Podkorytov 26

Last 30 days Overall leaderboard

Product updates

Dynamics 365 release plans