<p>I think what you're saying is that you only want to output the heading once it's different from the previous heading. So if you have two blocks with the same week, we only show it once.</p>

<p>You can set a variable of <code>week</code> and check that the current block's week (which I've set as <code>tempWeek</code> to keep code cleaner) is the same. If it isn't the same, it means we've changed week so display the title and then set week to be this new week.</p>

<pre><code>{% set week = "" %}
{% for block in entry.timeSheet %}
    {% set tempWeek = block.week|date('j M Y') %}
    {% if tempWeek!=week %}
        &lt;strong&gt;W/C: {{ block.week|date('j M Y') }}&lt;/strong&gt;&lt;br /&gt;
        {% set week = tempWeek %}
    {% endif %}
    {% if block.totalTime | length %}
        {{ block.totalTime }}&lt;br&gt;
    {% endif %}
    {{ not loop.last ? '&lt;hr&gt;' }}
{% endfor %}
</code></pre>

CC BY-SA 4.0
2018-08-28T17:02:57.767Z
Amazing! thanks
user2569
CC BY-SA 4.0
2018-08-28T17:00:20.080Z
2018-08-28T17:00:20.080Z
Mutual
<p>I think a better way to achieve this would be with Supertable, but for now I'm wondering if there is a way to group the example output </p>

<p><strong>W/C: 27 Aug 2018</strong> {{ block.week }}</p>

<p><strong>1.5</strong> {{ block.totalTime }}</p>

<p><strong>W/C: 27 Aug 2018</strong> {{ block.week }}</p>

<p><strong>2.5</strong> {{ block.totalTime }}</p>

<p><strong>W/C: 27 Aug 2018</strong> {{ block.week }}</p>

<p><strong>3</strong> {{ block.totalTime }}</p>

<p>instead like</p>

<p>W/C: 27 Aug 2018</p>

<p>1.5</p>

<p>2.5</p>

<p>3</p>

<p>so values from the 'number' field {{ block.totalTime }} 
which share the same value from the 'date' field {{ block.week }}
are somehow grouped together?</p>

<p>from the matrix fields in use below:</p>

<pre><code>     {% for block in entry.timeSheet %}

        {% if block.totalTime | length %}

        &lt;strong&gt;W/C: {{ block.week|date('j M Y') }}&lt;/strong&gt;&lt;br /&gt;
        {{ block.totalTime }}
        {% endif %}{{ not loop.last ? '&lt;hr&gt;' }}

     {% endfor %}
</code></pre>

<matrix>
Display matrix block which share the same date field value
# Display matrix block which share the same date field value

(Asked by: username_0 on 2018-08-28)

I think a better way to achieve this would be with Supertable, but for now I'm wondering if there is a way to group the example output 
W/C: 27 Aug 2018 {{ block.week }}
1.5 {{ block.totalTime }}
W/C: 27 Aug 2018 {{ block.week }}
2.5 {{ block.totalTime }}
W/C: 27 Aug 2018 {{ block.week }}
3 {{ block.totalTime }}
instead like
W/C: 27 Aug 2018
1.5
2.5
3
so values from the 'number' field {{ block.totalTime }} 
which share the same value from the 'date' field {{ block.week }}
are somehow grouped together?
from the matrix fields in use below:
     {% for block in entry.timeSheet %}

        {% if block.totalTime | length %}

        W/C: {{ block.week|date('j M Y') }}
        {{ block.totalTime }}
        {% endif %}{{ not loop.last ? '' }}

     {% endfor %}

**Tags:** matrix

---

## 1 answers

### Answer by username_1 on 2018-08-28. Score: 2 | Accepted answer

I think what you're saying is that you only want to output the heading once it's different from the previous heading. So if you have two blocks with the same week, we only show it once.
You can set a variable of week and check that the current block's week (which I've set as tempWeek to keep code cleaner) is the same. If it isn't the same, it means we've changed week so display the title and then set week to be this new week.
{% set week = "" %}
{% for block in entry.timeSheet %}
    {% set tempWeek = block.week|date('j M Y') %}
    {% if tempWeek!=week %}
        W/C: {{ block.week|date('j M Y') }}
        {% set week = tempWeek %}
    {% endif %}
    {% if block.totalTime | length %}
        {{ block.totalTime }}
    {% endif %}
    {{ not loop.last ? '' }}
{% endfor %}

> **Comments:**
> **username_0**: Amazing! thanks  

---

