Is this a bug in dataview?

I have two files:

  • File 1 test: this file contains tasks
  • File 2 test: this file contains 2 properties (current, total)

The goal is to make a table with progress bars using tasks count if there are tasks, or current/total if there is current and total property.

TABLE WITHOUT ID 
   file.link as "Subproject", 
  "<progress value='" + Progress  + "' max='100'></progress> "+ floor(Progress)+"%" AS "Progress", Progress as check
WHERE link = this.file.name 
FLATTEN choice(current,number(current/total*100),(length(filter(file.tasks.completed, (t) => t = true))/length(file.tasks.total)*100)) as "Progress"

This script produces the following result:

as you see only one file appears, but if i remove the “*100” then:

TABLE WITHOUT ID 
   file.link as "Subproject", 
  "<progress value='" + Progress  + "' max='100'></progress> "+ floor(Progress)+"%" AS "Progress", Progress as check
WHERE link = this.file.name 
FLATTEN choice(current,number(current/total),(length(filter(file.tasks.completed, (t) => t = true))/length(file.tasks.total)*100)) as "Progress"

it works… Can someone explain what’s happening? Thank’s.

Moved to help

So I don’t know what “choice” does, and I don’t know your inputs, so I’m not entirely sure.

I just wonder if it’s an order of operations. You might need number((current/total)*100) so you are multiplying current/total by 100, instead of dividing current by total*100.

Because a quick google tells me in Javascript, multiplication comes first. And I assume Dataview is the same. And from my memory of math class, multiplication and division are the same priority, so it’s best to bracket.

And I have no idea about integer math vs. float math in Dataview, but if I was in Python, I would be using 100.0 instead of 100, to make sure I’m doing proper float math and not rounding accidentally.

Nope… Both doing number((current/total)*100) and number((current/total)*100.0) makes the same result of post 1 photo 1.

I really don’t know how but now it works:

TABLE WITHOUT ID category as "Category",
   file.link as "Project", 
  "<progress value='" + Progress  + "' max='100'></progress> "+ floor(Progress)+"%" AS "Progress"
WHERE link = this.file.name 
FLATTEN choice(total and current,number(current/total),(length(filter(file.tasks.completed, (t) => t = true))/length(file.tasks.total)*100)) as "Number"
FLATTEN choice(Number>1,Number, Number *100) as "Progress"

I’m not sure if I’d call it a bug, but there is a case where if the intermediate calculation I’d null the row will be skipped.

This is most often seen when using choice() where either side of the result expressions produces either a faulty or a null value.

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