Missing data from dataview tables

What I’m trying to do

I am building a digital bookshelf with various ways to display the books. Within this, I have a page to display data on the books, no. of pages read, and a page where have a table with the books being currently read.

Things were going well when I noticed that sometimes the books or data that I want to be displayed do not appear.

Examples:

Currently Reading Section

There is only one book when there should be 2. Here is the other:

---
Tags: [book, fiction, sciFi,murderbot]
Cover: https://d1w7fb2mkkr3kw.cloudfront.net/assets/images/book/lrg/9781/2501/9781250186928.jpg
Type: [Fiction, Sci-Fi]
Series: The Murderbot Diaries
Order: 2
Author: [Martha Wells]
Status: Reading
Year: 
Pages: 149
CurrentPage: 15
OrderInYear:
Month: 
---

I noticed that for some reason all of the books in the series above do not appear and I can’t see why.

Books data

On this page, I have some data like the number of books read per year and the number of pages per year.

The number of books worked fine, but in the number of pages there is a missing year

Since one of the tables, there is showing all the years I can’t find any solution for this.

Can someone help here? Could it be a bug or something I am not doing right? Thanks!

For anyone to be able to help you fix any errors in your queries, we do need to see your queries…

Sorry about that! Completely forgot

The query for the first screenshot

table ("![coverimg|100](" + Cover + ")") as Cover, Author as Author, Type as Type, ("![progress + " + (round((CurrentPage/Pages)*100)) + " %](https://progress-bar.dev/" +(round((CurrentPage/Pages)*100)) + "/)") AS Progress
from "Books"
where Status = "Reading" AND contains(Type, "Fantasy") OR contains(Type, "Sci-fi") OR contains(Type, "Literature")
sort file.name ASC

The query for the second screenshot

TABLE sum(rows.Pages) as NumberOfPages
FROM #book 
GROUP BY Year

Does it work if the year key has a value?

image


Same result…

1 Like

It works locally with a localized testtag to use for from in the query:

---
Tags: [testtag, book, fiction, sciFi,murderbot]
Cover: https://d1w7fb2mkkr3kw.cloudfront.net/assets/images/book/lrg/9781/2501/9781250186928.jpg
Type: [Fiction, Sci-Fi]
Series: The Murderbot Diaries
Order: 2
Author: [Martha Wells]
Status: Reading
Year: 2003
Pages: 149
CurrentPage: 15
OrderInYear:
Month: 
---

```dataview
table 
("![coverimg|100](" + Cover + ")") as Cover, 
Author, 
Type, 
("![progress + " + (round((CurrentPage/Pages)*100)) + " %](https://progress-bar.dev/" +(round((CurrentPage/Pages)*100)) + "/)") AS Progress
from #testtag
where Status = "Reading" 
AND contains(Type, "Fantasy") OR contains(Type, "Sci-Fi") OR contains(Type, "Literature")
sort file.name ASC
```

The only thing I had to change from the query was contains(Type, "Sci-fi") to contains(Type, "Sci-Fi") – a capital F on Fi to match the YAML value.

Works in your vault with the same change?

Additionally, could use icontains(), the case-insensitive version of the function.

More at Functions - Dataview

1 Like

In addition to what @anon63144152 is saying, I would like to add that using icontains() would do in-case sensitive matching against the types.

Another interesting aspect with your WHERE clause can be illustrated with the following queries:

F and T: `= false and true`
==F and F OR T: `= false and false or true`==

T and F: `= true and false`
T and (F or T): `= true and (false or true)`

contains(), AbC vs aBc: `= contains("AbC", "aBc") `
icontains(), AbC vs aBc: `= icontains("AbC", "aBc") `

Which displays as:

image

The highlighted line illustrates the case where the Status is not reading, aka false, it’s not Fantasy but it is Sci-fi. This, I reckon, should not return a true status since you’re not reading that book currently.

The issue I’m getting at is that the logic I’m assuming you want is that the query should only return those having both a status of reading, and either of the allowed types. To achieve this, you need to add parentheses around the various OR clauses, as elsewise a random true statement in the latter list will make the entire clause true, as illustrated in the example above.

I’m not saying your overall query will fail due to this, but you’ll get some false positives every now and then when not reading a book which is one of the accepted types.

1 Like

*extreme facepalm*

@anon63144152 yes, it was because of that typo! Now it works fine, thanks a lot.

@juanbretti and @holroy thanks for the advice on improvement in the query. Now it is working much better.

Note: I also fixed the second issue. I was thrown back by the fact that 2021 appeared on one query and not on the other. Then I realized the the pages per year is a sum, so obviously there was missing data on some files.

Again, thank you for the help!

1 Like

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