Help with Obsidian Charts and Dataviewjs

Finally got the time to test your query and I’m getting the error

Dataview: Every row during operation 'where' failed with an error; first 3:

                - No implementation of 'dateformat' found for arguments: string, string
- No implementation of 'dateformat' found for arguments: string, string
- No implementation of 'dateformat' found for arguments: string, string

See my updated version above, if you’re using queryMonth in the frontmatter:

---
queryMonth: 2023-03
---

and if in the body text:

queryMonth:: 2023-03

So that was an error on my behalf, but how did you get it to be a string? What did you write in your note with the query, and the exact query?

OK, when I took a closer look at your modified query you kind of got the gist of it, but it was a point in the other query to actually make theMonth into a string for comparison purposes.

When you want to look at the days separately, it’s not that much of a point, so it could most likely be simplified a little:

```dataview
TABLE 
sum(map(rows.theDay, (r) => r[1])) as Created,       	
sum(map(rows.theDay, (r) => r[2])) as Closed 
FLATTEN array([Created, 1, 0], [Closed, 0, 1]) as theDay 
WHERE
  (contains(file.name, "INC") OR (contains(file.name, "SCTASK"))) 
  AND !contains(Created, null) 
  AND !contains(Closed, null) 

GROUP BY theDay[0] as Day
WHERE dateformat(Day, "yyyy-MM") = dateformat(this.queryMonth, "yyyy-MM")
```

Also note the crucial difference of doing this.queryMonth instead of just queryMonth, to make it only read that value from the current file containing the query.

Alternatively, you could modify your query variant with a WHERE clause of:

WHERE dateformat(date(Day), "yyyy-MM") = dateformat(this.queryMonth, "yyyy-MM") 

This would both remove the error messages, since it’s converting the Day which is a string back into a date, and compare it against the this.queryMonth instead of a (non-existent) `queryMonth in every file.

I am using in the frontmatter. I just copied and pasted your code. Didn’t change anything.

See my latest reply where I further corrected some of my errors coming from being not entirely awake today, and posting untested code. The last reply does contain tested code, so it should work now.

Yes it is. Thank you so much!!! And sorry for troubling you. I think that is all for now regarding Dataview. I’m having an issue with Obsidian Charts but that’s for another conversation.

I’m so sorry. Just one more thing. When I use that query it groups everything correctly but in the tables I am getting “November 02, 2022” on the day column and on the charts I’m getting “2023-03-01T00:00:00.000+00:00” on the columns. How can I mantain the group by results but format that column to be “yyyy-MM-dd”?

Maybe by doing:

GROUP BY dateformat(theDay[0], "yyyy-MM-dd") as Day
WHERE dateformat(date(Day), "yyyy-MM") = dateformat(this.queryMonth, "yyyy-MM")

This formats the date before group’ing, which should be OK, but then we need to use date(Day) to get it back to a date format (or alternatively the ugly rows.theDay[0][0] ) within the WHERE clause. Hopefully, either version should also propagate into Obsidian Charts with a nicer format.

I almost had it. Was missing the date(). Thank you once more.

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