Optimize / alter dataview query for a habit tracker

What I’m trying to do

I have a daily task with “Habits” section. Habits are represented by tasks and list items with metadata. Need to display summary in a table for the last 7 days.

Requirements:

  • Filter by section (Habits)
  • Filter by title of a habit
  • No hardcoded list positions, so whenever I add a new habit, it doesn’t impact the logic

Things I have tried

Note:

…

## Habits

- [ ] Cold shower
- [ ] Workout
- [x] Cardio
- Steps:: 10002
- Sleep:: 3
- Hydration:: 

Dataview query:

TABLE WITHOUT ID
	file.link AS "Day",
	choice(filter(rows.L, (t) => t.text = "Cold shower").completed[0], "✓", "✗") AS "💦",
	choice(filter(rows.L, (t) => t.text = "Workout").completed[0], "✓", "✗") AS "💪",
	choice(filter(rows.L, (t) => t.text = "Biking").completed[0], "✓", "✗") AS "🚴",
	choice(rows.steps[3] > 10000, "✓", "✗") AS "🚶",
	choice(rows.sleep[4] >= 8, "✓", "✗") AS "💤",
	choice(rows.hydration[5] >= 96, "✓", "✗") as "💧"
FROM "5 Daily"
FLATTEN file.lists as L
WHERE meta(L.section).subpath = "Habits"
GROUP BY file
LIMIT 7

Is there a better and less hardcoded way to achieve this?

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