Referencing a calculated dataview field in the body of a note in Dataview or TRacker plugins

What I’m trying to do

  1. I enter an array of data into a dataview field in the body of my daily note using the quickadd plugin; Example: “TimeNoted:: [0.5,1.5,3]”
  2. I sum that array using a dataviewjs script that outputs the aggregate value into a new dataview field in the same note; Example “TotalTimeNoted:: 5”
  3. Because the valueis calculated, I cannot store the data in the frontmatter of my daily note;
  4. I now want to reference the calculated value in the “TotalTimeNoted” field in a separate note using Dataview and/or the Tracker plugins to track daily time totals.

Things I have tried

  1. I have tried using dataview and tracker directly. They can both easily reference the ‘static’ data in the arrays and datfields of other notes - but cannot reference the calculated field(?);
  2. I have tried using Templater, to create new Daily Notes that output the calculated “TotalTimeNoted” for yesterday as a ‘static’ datafield in the new daily note (which could then be referenced) - but this does not work:
    2.1 Templater can easily read and output data-fields stored in frontmatter of other notes, but not in the body(?).
    2.2 I have tried Templater approaches using script based around app.metadataCache.getFileCache and tp.file.content.match(regex);

I have trawled through the forum, reddit, and search engines for days.
Thanks for any assistance

I just started doing this to add up calories in a recipe, and then make it available. It’s an inline dataviewjs command:

Calories:: `=round(sum(this.file.tasks.cal)/this.servings)`

Instead of having a separate dvjs script, could you just embed it like I have?

Thanks for your reply.
Not in front of my pc now, but will test ASAP. Are you able to reference the aggregate value of your “Calories” field directly in a dataview table on another page?

Ehh, I hadn’t tried that yet. On the same page, `=this.Calories` works, but when I go to a different page and use a Dataview table that includes Calories, nothing shows up.

Whenever you get to store inline queries to fields, remember that it’s the query which gets stored not the result of the query. This means that for this to work from other pages you’ll need to write the query as if it was on another page in the first place.

I.e. using this will always refer to the current file, whether it’s used directly in a query or indirectly through a stored query.

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