Issues with Arrays

So, I’m hitting a stumbling block while trying to pull the number of values in an array.

I have a number of fields that I’m using as inline data for notes that I’m referring to as tasks.

Type:: #Task

My issue is, sometimes the RelatedTo filed contains one value, no value, or multiple values. almost always the values are links to other notes.

My trying to run a dataview query that will give me the “count” of the number of entries in that field. The only way I can find to do that is with length(), but that only works with arrays. So…

If there are no entires, it gives me a null… which I can deal with.

If there are 2 entries, it gives me 2

However, if there is 1… it errors and doesn’t show ANY of the data for that file.

Can anyone offer some help on how to query it correctly.

BTW… the idea is to develop a priority scoring system where by the distance from the due date, the last modified time, the task priority and how many other things it is related to all contribute to a scoring priority of the task to see which ones require more attention.

Hi Someara23,

Yep, I’ve run into this issue too. The solution I came up with was to check the result and wrap it in an array if needed before I processed the result. But (as far as I know) that only works in a dataviewjs query.

Are you using a standard dataview query or a dataviewjs query?

I’ve been using a standard dataview query… more familiar with SQL than JS. :frowning:

One question: how you put multiple values in an inline field?
Arrays in inline fields? I think that’s not possible!
You have some (false) results because you are using links… but if you use any other expression, you’ll see that the length gives you the number of characters in the field.
For your intentions, you may need to create a field in YAML frontmatter with the correct syntax for an array:

example: [item 1, item 2, item3]


  - item 1
  - item 2
  - item 3

I will give that a try.

You can put link arrays into Dataview inline fields. I know of two different ways:

This file:

Array1:: [[Untitled]], [[Untitled]], [[Untitled]]

Array2:: [[Untitled]]
Array2:: [[Untitled]]
Array2:: [[Untitled]]

And this report:

TABLE Array1, Array2
FROM [[Untitled]]

Produce this output:


  1. As I mentioned before, links have a different behavior in inline fields. I don’t know if this is intentional or not (we need to ask to plugin developer). But in type 1 (“Array1”), if you work with other values (not links), you don’t get any array, just a simple string.
    The method used in type 2 (repeated “Array2”) works with links or anything else.

  2. But… so many issues (as the described by Someara23) seems to tell us that these inline-fields are not a “really” arrays. If you use the function length and have only one entry in your inline-field, then you get an error (because you don’t have any array and length requires it).

Yes, good point! If there’s only one item it’s a raw object, not an array of one.

I can deal with that in a dataviewjs by checking the result, but I don’t know how to manage it within a regular dataview block.

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