Get first item in list in dataview

Hi Team,

I am trying to figure out how to get the first item from the list of inlinks in my dataview query and can’t seem to find a function that will do the job.

My actual use case, is that I have a list of ‘Location’ notes, and these are linked to in my daily notes. I am trying to create a MOC, that lists the locations, in the order of time since I have been to that location, so oldest ones first.

I tried dataview over my dailynotes, but soon got in a knot, so am now trying a dataview over the locations, and want to use inlinks, on each location, but can’t work out the simple bit… how do I get the first link ? All of the example doco is simple stuff… is there a secret stash of complex examples? Or do we think the fact that I want to sort inlinks and then get the first one, is the sign that Dataview is the wrong tool for the job and I need to learn DataviewJS?

Thanks in advance

I’ve already answered this question in your other post:

For those locating this through searching, the trick to find a given element is either through direct indexing, or through using some of the list functions, like max(), min() (or preferably maxby() or minby(), if you need to look into a list of links for example).

Here are some code examples:

  • file.inlinks[0] – Will give you the first link in the list
  • reverse(file.inlinks)[0] – Since we reversed the list, we now get the last element…
  • maxby(file.inlinks, (f) => – Extract the latest date associated with any of the file.inlinks. Similar syntax can be used to pick your property of choice, e.g. f.myModificationDate

Regarding documentation you’ve got this forum when you learn how to search (which can be a little daunting), the main documentation site and also some of the resourced listed there (especially the example vault could be useful for some of the more advanced example queries).

1 Like

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