Bases: Detect duplicate property values accross notes

What I’m trying to do

I’m trying to make a base that detects notes that have a certain property value (called: id) that already exists in another note. The value could be anything, but when 2 notes have the same value, it should show up.

Things I have tried

Looked through the bases and function documentation, played around with the functionality but couldn’t find a way to do this.

Not sure I am looking at this the right way, but do either of these help at all?

```base
views:
  - type: table
    name: Table
    filters:
      and:
        - id.isTruthy()
    order:
      - file.name
      - id

```

```base
views:
  - type: table
    name: Table
    filters:
      and:
        - id.contains(this.id)
    order:
      - file.name
      - id

```

These don’t really help unfortunately, they just display all notes that have the id property filled. Well, the second only shows them if the id property type is text, which it’s not 'cause it’s a number type.

Maybe my first message was not super clear. I’d like to filter/find all notes that have the same value in the property called id. So for example, if 2 notes have id: 5, then they should show up in the list. If there are no notes that share a value in the property called id, no notes should show up.

I don’t know if this is possible with Bases. I’m afraid that the set of primitives you can apply is not enough for this case.

However, you can make it using dataviewjs:

const property = "id"; // Change this for the property you want to use

let pages = dv.pages().where(p => p[property]);
let groups = new Map();
for (let page of pages) {
  let value = page[property];
  if (Array.isArray(value)) {
    for (let v of value) {
      if (!groups.has(v)) groups.set(v, []);
      groups.get(v).push(page);
    }
  } else {
    if (!groups.has(value)) groups.set(value, []);
    groups.get(value).push(page);
  }
}

let sorted = [...groups.entries()]
  .filter(([_, group]) => group.length > 1)
  .sort(([a], [b]) => a.toString().localeCompare(b.toString()));

dv.header(3, `Elements with the same value in "${property}" property`);
for (let [key, group] of sorted) {
  dv.header(4, `Value: ${key}`);
  dv.list(group.map(p => p.file.link));
}

Basically this code gets all notes which have the given property, groups them based on the value of the property (each group is composed by all notes that have the same value), and the filters out the groups with a single element, keeping the ones with at least two elements. Then, for each group, it shows the value which is shared in the group, and a list of links to all notes in that group.

For example, I applied it to the property length which I use to store the number of pages in the books I track with obsidian. The result is all books with the same number of pages, in my case:

Not clear to me, but to match a property that is stored as a number:

```base
views:
  - type: table
    name: Table
    filters:
      and:
        - id == this.id

```

Thank you both for your help! I think I will need Dataview to achieve this, which is fine. I will use that :slight_smile:

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.