Can Task List be sorted based on the first 5 characters of a task description

Things I have tried

Looked into regx expressions

  • but do not understand how to select the first 5 letters of the task description.
    Looked into Dataview Functions.
    -did not find a function to extract the first 5 letters of a string.

What I’m trying to do

I have task added to the daily notes that have the project number (a 5 character string) embedded at the beginning of the tasks string.
Then sub tasks are added to each project on different days.

I like to have the task sorted by the project number (first 5 characters) the the task description.

If all the task descriptions start with the project code, can you just sort by description? Is that not producing the correct answer?

Thank you for your prompt reply.

Perhaps and image would help…

  • The first (7) characters contain the project number.
  • The rest of the line includes relevant project information (that will be the same every time)

I would like to use Daily Notes to keep a list of Project tasks by:

1- copy and paste the project information into a task line (from a master list)
2- add sub tasks as required/requested on that day.
3- have them listed as a Dataview (plugin) query of daily notes to create a master TO-Do List.

My Dataview query looks like this:


task
from #DailyNote 
where contains(string(section), "TGProjectLogs")
and
!complete
group by description
sort description desc

Problems:
1- How to sort the tasks based on the first (7) characters of the task description string.
2- How to group the subtasks based on the “main” task description.

Any ideas?

Thank you for your response.

It is not working because of the following:

  1. the result is not sorted ascending based on the description
  2. The Tasks are not being consolidated under one heading.
    (See image below).

Any ideas?

Thank you for the descriptions and the images. I understand much better now!

Of your two reasons for not working, the first one is easy to fix. You want to replace your line that is sorting with sort text asc. Dataview uses “text” instead of “description” for the contents of the task, and you said you want ascending instead of descending. Also put your sort before your group by if you want your groups to be sorted!

Consolidating is trickier. This will get you partway to what you want: replace your line that starts “group by” with:

group by substring(text, 0, 7).

Remember, you want this after your sort!
Substring is a dataview function that doesn’t show up in the documentation page for functions (there are a couple of these! Hopefully the documentation will get updated!). If you pass it a string such as the text of your task, and then tell it where in the string to begin and end it’ll give back just the portion between the beginning and ending. Starting at 0 includes the first character, ending at 7 means stopping after the 7th character.

So this gets you headings for your project codes. Any further consolidation is complicated. If I have an idea for it, I’ll come back and edit this post, but it likely won’t be until Monday in FL that I’d have time to think about it.

1 Like

One more thank you for your prompt response to my inquiry.
I appreciate your help as I am an old engineer trying new things.
(My office nickname is “the old dinosaur”).

I followed the suggestions listed in your response and updated the Dataview script as follows:

task
from #DailyNote 
where contains(string(section), "Invoices To Prepare")
sort text asc

and got the following result (the tasks were Sorted by the title of the daily note)

When I included the “group by substring(text, 0, 7)” at the end of the script I got the following error…


task
from #DailyNote 
where contains(string(section), "Invoices To Prepare")
sort text asc
group by substring(text, 0, 7)

image

That’s odd! I did test this on my vault before posting and it worked. Can you check that your Dataview plugin is up to date by going to Settings → Community Plugins → “Check for Updates” button, then Update on Dataview (or Update All) then close and re-open Obsidian? I just now had an update to Dataview when doing this process. Hopefully we will be on the same version now!

And as part of this update substring is now documented!

EDIT: @Puy I confirmed that the query, including group by substring(text, 0, 7) works for me on the latest Dataview. If it doesn’t work for you then I am really confused!

scholarInTraining,

one more time, thank you for your prompt response to my inquiry.

You were Right !!. (Needed to update Dataview - and some other plugins).

However, I ended up modifying the group statement to:

group by substring(task.text, 0, 7).

This way it only group the query results by the “task text” while ignoring the “sub-task text”.

1 Like

Hurrah, glad it is working!

Interesting! I think I understand the problem you solved with this (my apologies for not noticing the problem before - I am still getting a hang of how dataview handles subtasks) but I don’t understand why your solution works. Yay, a learning opportunity for me! Any chance you could share a screenshot of part of the results of the working version with the group by? Thanks!

ScholarInTraining:

Not a problem. I appreaciate very much your help.

I am making an effort to learn Obsidian because:

  1. It appears to be very flexible - not as rigid as a formal database. (like notion).
  2. Can autolink and organize data
  3. It appears to be extensible with the plug in
  4. and above all - I own the data.

So I am putting some time to learn more about it.
But I am a structural engineer - not a programmer - and documentation/examples seem to be light or gear toward the more advanced users.

If you have any insight or can point me in the right direction to learning resources would be very much appreciated.

Thank you for your help.

1 Like

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