What I’m trying to do
I have a dataview query that returns all the books I’ve read by a particular author. I have a folder note for each book, and in the properties of the book note I am tracking a number of data elements, including author, book cover image, date read, page count, and rating. My existing dataview query works well but it displays the rating as a number, and I would instead like to display the number of stars that correspond with the rating. I found this post and thought this would be my solution, but for some reason the query returns no results when I add in the FLATTEN statement.
Here is the code that works:
TABLE
("![](" + cover +")") as Cover,
series AS Series,
PageCount as Pages,
dateRead AS DateRead,
rating as Rating
WHERE author = [[Agatha Christie]] AND contains(file.tags,"book")
SORT title
Here is the code with the flatten statement I am trying to use:
TABLE
("![](" + cover +")") as Cover,
series AS Series,
PageCount as Pages,
dateRead AS DateRead,
r as Rating
FLATTEN {
"0": "",
"1": "★☆☆☆☆",
"2": "★★☆☆☆",
"3": "★★★☆☆",
"4": "★★★★☆",
"5": "★★★★★"}[rating] as r
WHERE author = [[Agatha Christie]] AND contains(file.tags,"book")
SORT dateRead desc
Things I have tried
I have tried this query with and without the SORT statement; I get the same result whether or not it is included. When the query does not include the FLATTEN statement it works perfectly, and when I add in the FLATTEN statement I don’t get any errors, but no results are returned. I have also tried including a FROM statement immediately before the FLATTEN statement (FROM “book”), but that doesn’t alter the result either.
I am using a css snippet to allow the query to display a card view in the results, but I have also tried this same query on a page that does not include the snippet and the results there are the same.
Here’s the result with the query that works:
Here’s the result when I add in the FLATTEN statement:
Any insight is much appreciated.