I want to create a table in dataview where I collect frontmatter from pages with a certain tag and output the ratio of the values in frontmatter. I can obviously do this with dataviewjs… but I would prefer not to do this as it defeats some of the purpose of the dataview query language (more typing, decreases understandability)
Things I have tried
I have the following query
```dataview
TABLE file.frontmatter.views as views, file.frontmatter.hours-up as hours FROM #pages
However when I run this I get the following error
Dataview: Every row during final data extraction failed with an error; first 3:
- No implementation found for 'string / string'
but I have set the property type to number in the frontmatter.
I tried using a "Number" function to convert strings to numbers - but this doesn't seem to work.
When you choose to use file.frontmatter.views and file.frontmatter.hours-up you’ll get the string value of these properties. If you on the other hand use views and hours-up you’ll get dataview’s automatic interpretation of the values.
So most likely, you could simply do TABLE views / hours-up ... and get the values you wanted (or possibly the other way around… ). Another way to handle it would be to convert the strings to number by doing number(file.frontmatter.views) and similar.
A formatting tip, if you enclose the dataview code blocks with lines with four backticks in front and after, the code blocks would display better in the forum.
Thanks for the tip, what I really want is a preview or edit button . Aha, I just needed to close the welcome message that was helpful covering up the preview box.
I tried Number (the standard javascriptway) but not number - which works perfectly.
TABLE views / hours-up from #pages
still complains about dividing a string by a string for some reason.
I’ve found the functions documentation in the dataview docs which documents number and seems to be what I was looking for.
I use something like this in my code which works find.
```dataview
TABLE views, hours-up, round(number(views) / number(hours-up), 2) as ratio FROM #pages
```
Yeah… it thinks that they are strings. Just I’ve set them to be numbers in the file-properties. Perhaps I should be using a “typed out” front matter rather than file properties.
.
If I use a prop::1 at the beginning of the file as described here then the type seems to be detected as a number.
Hmm… That’s kind of strange, as in my case the numbers are kept as numbers. In my test I actually used one as a duration, and that would also be available for calculations. So it could be that one of your property values are actually containing something else than numbers. Do you use units or something like that in your numbers? That would throw Dataview of its game, and cause the need for using number(views) or number(hours-up).