How can I restrict a dataview query to show incoming links from notes of a certain 'type'?

What I’m trying to do

I would like to find a way to run a dataview query table that shows me the number of incoming links to a note, but ONLY if the files linking to this note belong to a certain ‘type’.

Context: I’m thematically analyzing survey responses for a research project using an approach similar to Axle Design’s environment. Basically, I make a new note for each survey response (in a dedicated ‘data points’ folder with frontmatter that says “type:: datapoint”). Then, I write ‘theme codes’ that apply to each response at the bottom of the note as internal links. This creates notes for each ‘code’ (in a dedicated ‘codes’ folder with frontmatter that says ‘type:: code’).

I have a dataview query that shows me a table with the code names and the # of incoming links to those codes. I need this so that I can see which ‘codes’ come up most frequently in the survey responses:

TABLE without ID file.name as “Code”, length(file.inlinks) as “Data Points”
WHERE type= “code”
SORT length(file.inlinks) DESC

Now this gives me the number of ALL incoming links to every ‘code’-type note. Thankfully, right now those links are only coming from ‘datapoints’. However, I may need to link to those ‘code’-type notes from other files (for various reasons), but that’ll inflate the ‘length(in.links)’ values in the query table. Is there a way to limit the ‘length(in.links)’ value to only count files with the ‘datapoint’ type?

Try something like:

TABLE without ID
	file.link as "Code",
	IN AS "Data Points"
WHERE type = "code"
FLATTEN length(filter(file.inlinks, (i) => i.type = "datapoint")) AS IN
SORT IN DESC

An advice: if possible, add a source filter like FROM "your-folder-path" (because performance issues).

Hi! I’m trying to adapt your response for my table.
I want to list my contacts, and in one column show the last 5 inlinks created (if any).
Is something like you responded in the right path? That AS IN?
Thanks!!

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