Using Tracker searchTarget in dataview

Hi guys,

I use the Tracker-Plugin to log some habits, body or mental issues, like my stress_level in my daily notes.
To log it (from 0-10), I use the value-attached tag field:

#log/dailyQuestions/stress_level:5 

(=> if I have a medium stress level, like 5 on a scale from 0-10)

Now, additionally to the nice graph-view of the Tracker plugin, I want to analyze my log in a dataview-table, where I can add some more key-value-pairs to the daily notes (for example “stress_level_comment::”).

Here is my question:
Is it possible to analyze the value-attached tag field from above in a dataview?

I tried this, but it didn’t work:

```dataview
TABLE 
	log/dailyQuestions/stress_level, 
	stress_level_comment
From "Daily notes"
Where log/dailyQuestions/stress_level > 0
SORT file.name DESC
```

Thanks in advance,
kind regards,
Silias

How do you write that in your markdown? A tag can’t be given a value normally, and if it’s given a value it normally isn’t a tag, so what have you actually written in your notes?

Bonus tip: How to present code properly in a forum post

If you want to showcase either markdown, or code blocks, or dataview queries properly in a forum post, be sure to add one line before and one life after what you want to present with four backticks, ````. This will ensure that any other backticks (like for code blocks) is properly shown.

Hi Holroy,

thanks for your answer and your tip! :slight_smile:
=> I directly edited my original post, for better readability… :wink:

you asked, how I write that in markdown?
=>

#log/dailyQuestions/stress_level:5

As far as I understand, the tag #log/dailyQuestions/stress_level get the value 5 attached, see the doc of the tracker-plugin here

=> So, as I asked in my previous post: Do you think it’s possible to analyze the value-attached tag field from above in dataview, and if yes, how? :slight_smile:

To define a dataview field, you need to do one of these:

---
fieldA: myValueA
---
fieldB:: myValueB

Doing just #log/dailyQuestions/stress_level: 5 in the body text doesn’t define a dataview field, and can as such not be read from neither a dataview query, nor the tracker plugin.

So doing the following:

#log/dailyQuestions/stress_level:: 5

`$= dv.span( dv.current() ) `

In a file, reveals that the following are true:

  • It does make the #log/dailyQuestions/stress_level into a tag, as seen in both file.etags and file.tags
  • It creates a dataview field named: log/dailyQuestions/stress_level with a value of 5
  • It normalises and created a dataview field named: logdailyquestionsstress_level with a value of 5

Accessed from dataviewjs

Further more, if we try to access this as from a dataviewjs query:

with slashes as object field: `$= dv.span( dv.current().log/dailyQuestions/stress_level ) `
with slashes as reference: `$= dv.span( dv.current()["log/dailyQuestions/stress_level"] ) `
normalised: `$= dv.span( dv.current().logdailyquestionsstress_level ) `

we get the output:

Notice how the first variant doesn’t work since it contains slashes, and they are not very good to include in a field name.

Accessed from a DQL query

However, you used a DQL query in your original post, and then either of these incantations would work to get the value of it:

```dataview
TABLE row["log/dailyQuestions/stress_level"], logdailyquestionsstress_level, stress_level_comment
TABLE 
	log/dailyQuestions/stress_level, 
	stress_level_comment
FROM "Daily notes"
SORT file.name DESC
```

NB! I simplified the query here, but do use your original query just correct with the new variant to get the actual field value.

So I guess that if you want to use it with the Tracker plugin, you probably should use the logdailyquestionsstress_level variant, and in a DQL query, you could use either. I tend to see the row["..."] variant as slightly more readable. (And even better would be to use a better field name without the slashes)


In summary, to make it a proper field in the body of your note you need to use two colons. And then to refer to it you need either to use the normalised variant, logdailyquestionsstress_level, or the row["log/dailyQuestions/stress_level"] to get the value of it. And I reckon you’ll need to use the first variant within Tracker definitions.