Query for displaying tasks grouped by hashtags or parent's hashtags

I’m new to Logseq, but trying to figure out how to get my desired workflow work in Logseq.
In brief, I’d like to have a template for daily pages, where I see a “snapshot” of my current TODOs.
Since I used other note-taking apps since long ago and progressively migrated all my knowledge from one to another, eventually landing in Logseq these days, my knowledge base is about 2GB now and I use hashtags to label information, group and retrieve it later. Therefore, I need Logseq queries to retrieve information based on task hashtags, not page names (nor page hashtags), so that it works with my existing knowledge base (going over existing tasks/files and re-formatting them only in order to make Logseq happy is not an option for me).

The first step for me would be to fetch tasks and group them by hashtags, which I can’t figure out how to do yet even though I went through quite a few Logseq resources/articles/videos already. A task can either be tagged with a hashtag explicitly (i.e. - LATER do smth smth #life/errands) or inherit hashtag from a parent. Tasks with no hashtags are of no interests (considered to be the highest-granularity substeps which don’t need to be re-surfaced).

This seems to be the closest post to what I’m trying to achieve and it’s unanswered since Feb '22. However, I need the query to group by all found hashtags, not only those specified in the query.
Is this even possible? Would appreciate any help or pointers here…

Welcome.

What does this mean? When a task has more than one tag, which group should it go into? The other post groups by a single tag, that of the client’s id.

Both, I guess… At least as the first iteration, this will suffice.
The task will be printed in both groups, which is fine.

Your scenario doesn’t sound typical, but here is a proof-of-concept:

#+BEGIN_QUERY
{
 :query [:find ?res
 :where
   [?page :block/name ?page-name]
   [?block :block/page ?page]
   [?block :block/marker ?marker]
   (or-join [?block ?ref]
     [?block :block/refs ?ref]
     [?block :block/path-refs ?ref]
   )
   [?ref :block/original-name ?ref-name]
   [(!= ?ref-name ?marker)]
   [(!= ?ref-name ?page-name)]
   [?block :block/content ?content]
   [(str ?ref-name ": " ?content) ?res]
 ]
 :result-transform sort
}
#+END_QUERY

Thank you for your help @mentaloid , appreciate it!
This seems like a push in the right direction, however the query does not group tasks under hashtags. The goal is to have hashtags organized as sections, where each task is shown in a list.

To better illustrate what I’m trying to achieve, let me use an example of when you click a hashtag – a new view is opened and in it, you’ll see all the blocks that reference this hashtag. Basically, I need the same functionality, except a) for a given hashtag only show blocks that contain tasks in them, b) ignore hashtags that aren’t referenced by blocks with tasks (i.e. these are non-actionable hashtags) and c) on a daily page, render actionable hashtags as sections with task blocks as lists (i.e. tasks are grouped by a hashtag they reference).

I played with your query a bit, however haven’t been able to produce anything meaningful yet.
Also, this person seems to have a similar idea in mind.

Ideally, I would see the results as something like this (based on my current tagging):

## #greece/taxes/refund
	- NOW where's my refund [[greece/taxes]] #greece/taxes/refund
		- none of the sites have any notifications...
			- ![image.png](../assets/image_1709580288068_0.png)
			- ![image.png](../assets/image_1709580294852_0.png)
		- how can i check the status ? was it even accepted
		- NOW waiting on tax accountant reply...

## #investing/portfolio
	- LATER [#A] [[investments]] #investing/portfolio
		- LATER understand whether options can be exercised without the requirement to buy stocks
		- LATER invest in chips ?

## #investing/portfolio/optimization
	- got some links from @Brad on #investing/portfolio/optimization
		- LATER review these links
			- https://...
				- https://...
				- https://...

...and so on...

A step further would be to have sub-hashtags as sub-sections.

What you are asking for is not a query, but a report, made out of multiple queries (one for each tag, plus one to gather the relevant tags), then combining their results through a specific type of view. Each one of those queries is not too complicated (neither too simple), but their combination needs nothing less than a script. Logseq’s queries support some scripting, but they are the wrong tool for multistage reporting. Should rather use Logseq’s API to gather the data, then custom code to combine them into the desired report. Things would be easier if you decided to drop some of the requirements, but given the size and nature of your data, it’s probably not worthy to go for anything less.

1 Like

I see… Thanks for the input!
I was able to get something close to what I need in Obsidian using dataview/dataviewjs, however faced a problem that tags belong to the whole page rather than a section/list (or “block” in “Logseqish”) which resulted in fetching unneeded tasks as well.

I get where you are coming from, I have faced the same issues when I tried to manage my tasks in Logseq.

After some months of banging my head with queries and struggling to find a workflow that would work for me I gave up and started using a more suited tool for the job (Tick Tick, which I highly recommend).

After using Tick Tick, it became even clearer that Logseq would not work as a task management tool for me.
I like to treat my task list like a backlog, to which I add many tasks that may or may not be eventuay selected to be done, and they relate to many different subjects.

So my requirements are:

  • I need do be able to group/sort all my tasks by subjects (hashtags, in Logseq context)
  • I need to be able to group/sort all my tasks by priority
  • I need to be able to do both the above, at the same time, to have a clear picture of my backlog
  • I need to be able to “select” the tasks I am going to prioritize in a given week or month

With Tick Tick I can do that flawless, while with logseq, I woul need to spend a lot more time just to make a part of this workflow works.

So, I am sorry to disappointing you, but at least in my experience, Logseq task management features are only suitable for simple workflows.

I still use Logseq to take my notes, though, but the tasks are managed in Tick Tick.

Hope this helps