Query bulleted dates and/or tag under a specific header: advice

So the other reply I mentioned here was related to task, and not directly just list items:

(I also found a similar thingy by @mnvwvnm (which I’ve not seen for very long. Miss him), see Pulling tagged list items from particular file and showing their direct section heading? - #4 by mnvwvnm

So I found some time, and did some testing, and the “humidifier” test file looks like this:

---
type: appliance
---
### Maintenance log

- 2022-12-28 - 水内部クリーン (初めて)
- 2023-01-27 - manually wiped filters and dust boxes.....
- 2023-02-28 - 水内部クリーン (14:22~18:25) 

### Something else

- 2022-12-20 - Bought the humidifier
- 2023-01-25 - Wife complied about noise
- 2023-02-27 - It dripped on the floor...

Nothing fancy in there, besides another section, and a “type: appliance” field in the frontmatter. This is to limit the “global” search later on since we’re expands all list items into separate rows. So having some kind of limiter is better for performance. Could be a field like I’ve used, or a tag, or just that the appliances are within a given folder and then you’d use FROM in the queries below.

The evolution of the query

Just to let you in a little bit on how I’m thinking when developing something like this, it’s an evolution of the script starting from gathering all the needed data, more specific information, before fine tuning the queries for nicer display.

The entire test file (except for the final query) is shown below:

## All list items in all appliances

```dataview
LIST file.lists.text
WHERE type="appliance"
```

## All table query of items in all appliances

```dataview
TABLE item.text, item.section, meta(item.section)
FLATTEN file.lists as item
WHERE type="appliance"
```

## Limited to the Maintenance section

```dataview
TABLE item.section, item.text
FLATTEN file.lists as item
WHERE type="appliance"
  AND lower(meta(item.section).subpath) = "maintenance log"
```

With another humidifier in the 2nd floor, this produce the following output:

(Snipped some parts of the second table, and the last query gave: )

Hopefully, you’ll grasp my way forward, the real simplified explanation is:

  • Use FLATTEN file.lists as item to get access to each bullet point as a separate item
  • Use the meta(item.section) to get to the parts of the link, and to locate that we’re wanting to focus on the subpath part
  • Do a lower(...) just to lowercase the header, and make sure we don’t miss out if someone write “MAintenance Log” or similar
  • And then a little fiddling with the output

The final query I ended up with was:

```dataview
LIST rows.item.text
FLATTEN file.lists as item
WHERE type="appliance"
  AND lower(meta(item.section).subpath) = "maintenance log"
GROUP BY link(item.section, file.name) as myFile
SORT meta(myFile).display
```

Which produces this output for me:

(And might I point out that you got really good working on that humidifier in the second floor… :slight_smile: )

Also notice some extra trickery in that last query:

  • Using GROUP BY link(item.section, file.name), to create a new link directly to the relevant header, but using the actual filename as the display text.
  • Reusing the GROUP BY field to sort according to file name
  • Before I used GROUP BY I could list each item using just item.text, but since we’ve now grouped the query, we need to use `rows.item.text``

Hope this helps sorting out what type of maintenance you’ve down on your appliances, and also that you’ve learned something related to how to evolve your queries from a basic list to just the thing you want.

10 Likes