How to *keep* duplicates in a filter?

Scenario: Several tiddlers have a myfield field. Most tiddlers have unique myfield values, but a few have identical and arbitrary values like myfield: foo, some have myfield: bar, etc.

How can I make a table that lists only those field values that appear in multiple tiddlers and, next to it, all tiddlers that have this field value, like so:

image

The only approach I can come up is problemtic because, for once, duplicate titles must be kept in the filters and I must also count them to insure they are indeed duplicates. But maybe this approach is off to begin with…?

Thanks!

I’m not sure how this will scale, performance-wise, but try this:

<table>
<$list filter="[each[myField]get[myField]] :filter[all[tiddlers]myField<currentTiddler>count[]compare:number:gt[1]]">
<tr>
<td><<currentTiddler>></td>
<td>

{{{ [myField<currentTiddler>] }}}

</td>
</tr>
</$list>
</table>
2 Likes

etardiff’s is probably better, but since I was also working on it, I’ll post mine which uses a variable instead of [all[tiddlers]] step:

<table><$list filter="[has[myfield]get[myfield]unique[]sort[]]" variable="fieldvalue"> <$list filter="[myfield<fieldvalue>count[]compare:number:gt[1]]">
<tr><td><<fieldvalue>> </td><td>{{{ [myfield<fieldvalue>] }}} </td></tr></$list></$list>
</table>
2 Likes

@etardiff and @Springer - thank you both! They both work, and it is quite educational to compare them side by side (…or, really, vertically):

<table>
<$list filter="[each[myField]get[myField]]
  :filter[all[tiddlers]myField<currentTiddler>count[]compare:number:gt[1]]">
<tr>
<td><<currentTiddler>></td>
<td>{{{ [myField<currentTiddler>] }}}</td>
</tr>
</$list>
</table>

<table>
<$list filter="[has[myField]get[myField]unique[]sort[]]" variable="fieldvalue"> 
<$list filter="[myField<fieldvalue>count[]compare:number:gt[1]]">
<tr><td><<fieldvalue>> </td>
<td>{{{ [myField<fieldvalue>] }}} </td>
</tr>
</$list>
</$list>
</table>

The main difference is that of a compound filter vs nested listwidgets.

Much appreciated.

2 Likes

I’ve just written something similiar for my own use. Instead of counting each unique value, it uses the difference between the list of values including duplicates, and the deduplicated list to extract the duplicates:

<$let allValueList={{{ =[has[myField]get[myField]format:titlelist[]] +[join[ ]]}}}  >
    <table>
       <$list filter="=[enlist:raw<allValueList>] -[enlist<allValueList>]" variable=dupvalue >
              <tr><td> <<dupvalue>> </td><td><<list-links filter:"[has[myField]field:myField<dupvalue>]" >></td></tr>
       </$list>
    </table>
</$let>

This is the version I used, placed in a procedure. I found it useful immediately in all my other TWs and thought it might be worth flogging a dead thread :

\procedure findDuplicate( fieldToCheck )
<$let allValueList={{{ =[has<fieldToCheck>get<fieldToCheck>format:titlelist[]] +[join[ ]]}}} >
    <$list filter="=[enlist:raw<allValueList>] -[enlist<allValueList>]" variable="dupValue" >

!!! <<dupValue>>: 
          <$transclude $variable="list-links" filter=`[field:$(fieldToCheck)$[$(dupValue)$]]` />
    </$list>
</$let>
\end

<<findDuplicate "myField">>