Query for all TODOs grouped by tag?

I have been using the journal to create my todos, by creating a tagged line, and then listing todos below that. Eg:

2021-07-04
- The new light fixture arrived for the [[Garage]]
  - TODO Install new light fixture
  - TODO Move light switch closer to the door
2021-07-01
- I have upgraded [[NextCloud]], next I need to
  - TODO Add secondary media type for local backup
  - TODO Add cloud storage for remote backup of critical files
  - TODO Enable SSL 
2021-06-25
- I have ordered a new light figure for the [[Garage]] 

When I go to the [[TODO]] page I see a very wordy list of Linked References. Eg:

2021-07-04
The new light fixture arrived for the [[Garage]]
- TODO Install new light fixture
The new light fixture arrived for the [[Garage]]
- TODO Move light switch closer to the door
2021-07-01
I have upgraded [[NextCloud]], next I need to
- TODO Add secondary media type for local backup
I have upgraded [[NextCloud]], next I need to
- TODO Add cloud storage for remote backup of critical files
I have upgraded [[NextCloud]], next I need to
- TODO Enable SSL 
2021-06-25
I have ordered a new light figure for the [[Garage]] 

Is there a better way to show these with a query? I can create a query for all tasks, but any attempt to group by tag does not work. Ideally I would be able to group by tag, and then sort by priority within those groups. Eg:

Tag [[Garage]] (2 tasks)
- TODO Install new light fixture
- TODO Move light switch closer to the door
Tag [[NextCloud]] (3 tasks)
- TODO Add secondary media type for local backup
- TODO Add cloud storage for remote backup of critical files
- TODO Enable SSL 

Before LogSec I did this manually, using this extension for VSCode, which worked really well. But it required direct manipulation of the file, so if it wasn’t on that page it was never seen, and when on the actual information page for the project it wasn’t seen there either. Todo+ - Visual Studio Marketplace

Or, if there is a better way for project management please point me to the reference/guide/video.

I do this:

{{query (and (todo now doing) [[imp-urg]])}}

The [[imp-urg]] part is a tag that I use as a sort of contextual prioritization technique, so the I use the same query but with other tags lower on the page.

I also change the now doing part to later todo for prioritization purposes. Could also just use todo without those parts to show everything.

2 Likes

Thank you. I struggle with the search terms a lot, it seems overly complex, and I don’t know if my search is wrong or LogSeq is broken. Based on yours for the Priorites TODO [#A] Test task I’ve gone with

{{query (and (todo todo) [[A]])}}
2 Likes

But is it possible to make a query witch will show only that blocks with TODO which contain one of a tagA or tagB?

I tried :
{{query (and (todo todo doing now later ) ( or [[tagA]] [[tagB]] ) ) }}
But Logseq shows me all my blocks with TODO. But I want only blocks that contains either tagA or tagB

How can I solve this?

Surprisingly, this works:
{{query (or (and [[tagA]] (todo todo doing now later)) (and [[tagB]] (todo todo doing now later)) ) }}

Still looking for a less silly solution…

2 Likes

Thanks Alex. It is really helped me to solve the problem.
But it is difficult to add tagC, tadD, tagE. Then I will need to add many (and [[tagName]] (todo todo doing now later)) for each of the tag. It’s not that convenient.
But it will be nice to be a standard solution from logseq

Personally, as soon as queries get bigger, I prefer advanced queries, this one is a good template:

#+BEGIN_QUERY
{:title "Find: tagged tasks"
:query [:find (pull ?b [* {:block/_parent ...}])
:where
	[?b :block/marker ?marker]
	[(contains? #{"LATER" "NOW"} ?marker)]
	  
	[?b :block/ref-pages ?p]
	[?p :block/name ?tag]
	[(contains? #{"kdrama" "cdrama"} ?tag)]]
}
#+END_QUERY

The two contains lines can be used to expand/change the query

3 Likes

Doesn’t return anything for me… I try this since months. It simply doesn’t return anything. Null. Nil. Empty. Call it as you want.
I wanna have a structure like my clients numbers sorted. Let’s say i have the following todos in my Journal Today:
TODO Do something for him #Client102030
TODO Do another #Client102030

Journal Yesterday:
TODO Do that #Client102030
TODO Make something for that #Client123456
Journal last Wednesday:
TODO Blabla 1 #Client445566
Journal last Tuesday:
TODO Blabla 3 #Client445566
TODO Time for tee with another #Client203040
TODO Blabla 2 #Client445566

and so on and so forth.
Now i wanna have a page with a Query that gives me all tasks that show me all tasks in state “TODO”, “NOW”, “DOING”, “LATER” (so all flavours fit; of course i can only use one of both) and get them sorted by tag so i have an overwiew over the clients. So the answer to the query - regardless of the day - should look like this:

#Client102030
TODO Do something for him #Client102030
TODO Do another #Client102030
TODO Do that #Client102030
#Client123456
TODO Make something for that #Client123456
#Client203040
TODO Time for tee with another #Client203040
#Client445566
TODO Blabla 1 #Client445566
TODO Blabla 3 #Client445566
TODO Blabla 2 #Client445566

I don’t find any approach to reach this goal. In my opinion there are better ways out there than datalog.
So if anybody knows how to get it done, i would be really happy but at this point i’m seriuously not impressed with datalog. Even the advanced queries in the docs don’t work fully. It works only with tags if you provide them as property in the page.

2 Likes