Count All Tasks And Done Tasks

i have this two categories of tasks on my Note:

PHP

  • [ ] Data Types (taskLabel::LearnPHP)
  • [x] Variables (taskLabel::LearnPHP)
  • [ ] Arrays (taskLabel::LearnPHP)

JS

  • [x] Arrays (taskLabel::LearnJavaScript)
  • [ ] Variables (taskLabel::LearnJavaScript)
  • [ ] Data Types (taskLabel::LearnJavaScript)
  • [ ] Functions (Task::LearnJavaScript)

What I’m trying to do is making a progress bar for my tasks on my statistics note

```dataview
TABLE WITHOUT ID "<progress class='red_blue' max=100 value="+Percentage+"> </progress>­ " + Percentage +" %" AS Progress,Total, Done ,Undone
FROM "Journal/Daily"
FLATTEN length(filter(file.tasks.status, (x) => x ="x")) as Done
FLATTEN length(file.tasks) As Total
FLATTEN round(Done / Total * 100) as Percentage
FLATTEN round(Total - Done) as Undone
WHERE date = date(today)

The above code works great but it outputs the value of Total = 7 and Done = 2
Because it works on all tasks in my note

what i want to do:

i want result of my work only on tasks with taskLabel = LearnPHP

Things I have tried

I have tried WHERE date = date(today) AND taskLabel = “LearnPHP”
but i got that Dataview: No results to show for table query.

For inline fields, check if the file contains the field; can you try this?

{...}
WHERE date = date(today) AND contains(tasklabel, "LearnPHP")

What does the date = date(today) do in your case? Have you set the field date for each file? If so, I’d rather use file.day, but that’s not the main issue.

You’re using a TABLE and not a TASK query for this, and that means that you need to go through the file.tasks list to get to each of your tasks. If you only wanted one result in this query, you could try doing a filter on the tasks as a first FLATTEN to get only those tasks to work with later on.

If you want multiple results, like to see the progress on both javascript and PHP, I would first FLATTEN the file.tasks lists, and then group on the taskLabel on your flattened task items.

First option with only one result

For the one result query, e.g. only LearnPHP tasks, something like the following should work:

```dataview
TABLE WITHOUT ID "<progress class='red_blue' max=100 value="+Percentage+"> </progress>­ " + Percentage +" %" AS Progress,Total, Done ,Undone
FROM "Journal/Daily"
FLATTEN array(filter(file.tasks, (t) => t.taskLabel = "LearnPHP")) as currTasks
FLATTEN length(filter(currTasks, (t) => t.status ="x")) as Done
FLATTEN length(currTasks) As Total
FLATTEN round(Done / Total * 100) as Percentage
FLATTEN round(Total - Done) as Undone
WHERE date = date(today)
```

Untested, but hopefully working, and you hopefully understand what I’m trying to do, so you could correct any typos

Second option for multiple results

These is also untested, and might probably contain some errors:

```dataview
TABLE WITHOUT ID  key, "<progress class='red_blue' max=100 value="+Percentage+"> </progress>­ " + Percentage +" %" AS Progress,Total, Done ,Undone
FROM "Journal/Daily"
FLATTEN file.tasks as task
WHERE date = date(today)
GROUP BY task.taskLabel
FLATTEN length(filter(rows.task, (t) => t.status = "x")) as Done
FLATTEN length(rows) as Total
FLATTEN round(Done / Total * 100) as Percentage
FLATTEN round(Total - Done) as Undone
```

(Note that your example has just Task:: ... for the “Functions” line, so if that’s real data, you’ll experience that it’ll not be grouped with the others)

I tried it but that target all task on the note

Thank you for providing a solution your solution works very well but after a many attempts today to find a solution I got a solution for it but think it is a bit difficult but it works

```dataview
TABLE WITHOUT ID
"LearnPHP" AS taskLabel,"<progress class='"+array("red","yellow","blue","green","green")[id]+"' max=100 value="+Percentage+"> </progress>­ " AS Progress, Done ,Undone,Total

FROM "Journal/Daily"
FLATTEN "LearnJavaScript" As targetLabel
FLATTEN length(filter(file.tasks.taskLabel, (x) => x = targetLabel )) AS Total
FLATTEN length(filter(filter(file.tasks, (task) => task.status = "x"), (task) => task.taskLabel = targetLabel)) as Done
FLATTEN round(Done / Total * 100) as Percentage
FLATTEN round(Total - Done) as Undone
FLATTEN number(regexreplace(string(Percentage/25), "\..*$", "")) AS id
WHERE date = date(today)

As you can see I used array because I only found the choice function
It will not be appropriate in this case
And also regexreplace because I only found the round function and it required the use of the floor function.

I would greatly appreciate any suggestions or insights you might have to enhance my solution.
Thank you again :slight_smile:

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