Difficulties with Dataview to show habit status in daily notes - table

I have searched everywhere but I can’t find the correct syntax. I have a daily notes template. A list of habits that are in task appears in it. I complete each one or not. So I want to make a dataview where in the first column the daily notes appear in the columns for each different habit. but I can’t create the syntax that says: if the habit is completed, a positive symbol appears and if not, a negative one.

this is what my habits look like:

habits #hab

  • run
  • to meditate
  • drink water

So far this is how I go:

table without id 
	file.link as date,
if, replaced, etc. and I get an error. I’m doing something wrong and I don’t know. exameple: choice(task.name.contains("run) && task.isCompleted, “:heavy_check_mark:”, choice(task.name.contains(“run”) && task.isComplete, “:x:”, “”)) as run
From #hab

it gives me an error

We need to see an example or two on how a daily note is defined, but something like the following might do the trick:

```dataview
TABLE runC as Run, meditateC as Meditate, waterC as Water
FROM "Daily notes" 
FLATTEN file.tasks as task

WHERE any(map(list( "run", "to meditate", "drink water"),
  (m) => contains(task.text, m) ))

FLATTEN choice(contains(task.text, "run"), "OK", "-") as runC
FLATTEN choice(contains(task.text, "to meditate"), "OK", "-") as meditateC
FLATTEN choice(contains(task.text, "drink water"), "OK", "-") as waterC
```

Query is untested, but it might work and/or help you get going on one way of solving your issue.

It doesn’t work for me, it looks like this:

TABLE runC as Run, meditateC as Meditate, waterC as Water
FROM #daily
FLATTEN file.tasks as task

WHERE any(map(list( “run”, “to meditate”, “drink water”),
(m) => contains(task.text, m) ))

FLATTEN choice(contains(task.text, “run”), “OK”, “-”) as runC
FLATTEN choice(contains(task.text, “to meditate”), “OK”, “-”) as meditateC
FLATTEN choice(contains(task.text, “drink water”), “OK”, “-”) as waterC

There are 2 things I need help correcting.
rows first:
You see 3 lines on the same page, the idea is that you see a single row per date. So:
image

second:
It does not work when completing the task it does not change to ok. The idea is that when completing the task, ok can appear and if not, it says no or something like that.

Both of your issues are related to the FLATTEN file.tasks as task in my original query, which splits out the tasks into their separate items. Aka make three rows for each attribute you want to track. To handle that we either need to start doing any(map(file.tasks, ...)) stuff, or do some other magic to regroup the result into a single line again by doing GROUP BY file.link and some extra magic to collate the result.

A non-flattened version

To do this the “proper” way you need something like the following:

```dataview
TABLE runC as Run, meditateC as Meditate, waterC as Water
FROM "Daily notes" 
FLATTEN file.tasks as task
WHERE any(map(list( "run", "to meditate", "drink water"),
  (m) => contains(task.text, m) ))

FLATTEN choice(contains(task.text, "run"), "OK", "-") as runC
FLATTEN choice(contains(task.text, "to meditate"), "OK", "-") as meditateC
FLATTEN choice(contains(task.text, "drink water"), "OK", "-") as waterC
```

But it turns out that Dataview’s contains() can do some stuff behind the scenes for us:

```dataview
TABLE WITHOUT ID file.link as "Daily note", runC as Run, meditateC as Meditate, waterC as Water
FROM "Daily notes" 
WHERE any(map(list( "run", "to meditate", "drink water"),
  (m) => contains(file.tasks.text, m) ))

FLATTEN choice(contains(file.tasks.text, "run"), "OK", "-") as runC
FLATTEN choice(contains(file.tasks.text, "to meditate"), "OK", "-") as runC
FLATTEN choice(contains(file.tasks.text, "drink water"), "OK", "-") as runC
```

On a related side note

Have you scanned the community plugins for alternative tracker plugins? There exists a whole lot of them with different focus. Just for the fun of it I installed the Habit tracker 21 plugin, and created the files “Habits/run”, “Habits/to meditate” and “Habits/drink water”, and ran the default variation over it (and clicked on various days in the table) and it displayed this table for me:
image

That’s kind of nice variant I think, and it’s easy to see streaks and correct if you did or didn’t do a habit the previous day(s) or not. I’m actually considering whether I’ll start using this in my own vault! :smiley:

Indeed the plugins saved me. It looks amazing and I was able to add icons and group by type of habits. so I remain:

Thank you very much for the help, the plugin was a good recommendation.
I have to organize my life haha

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