Help with DataView and DataViewJS

Hello, I need to retrieve information from .md files based on inline tags as below (Ticker).

Source .md files under Stocks/Data folder:


tags:
ticker: [“BMO.TO”]

Current querying .md file:

Notes:: My notes
Ticker:: BMO.TO

My ideal scenario would be for this to work:
TABLE WITHOUT ID name
FROM “Stocks/Data”
WHERE (ticker = this.Ticker)

the issue is that it doesn’t return anything.

The below works but it returns results which are not for example when Ticker = “BMO.TO”

TABLE WITHOUT ID name
FROM “Stocks/Data/”
WHERE contains(ticker, this.ticker)

I also tried this but it doesn’t work because the “this.Ticker” doesn’t seem to be returning BMO.TO as it’s in the inline tag.

dv.table(["Name"], 
dv.pages('"Stocks/Data"') 
	.where(b => b.ticker == this.Ticker) 
	.map(b => [b.name]))

This works:

dv.table(["Name"], 
dv.pages('"Stocks/Data"') 
	.where(b => b.ticker =="BMO.TO") 
	.map(b => [b.name]))

Can someone help me pls?

I can help only in DQL queries, not JS.
Let’s start with your query:

TABLE WITHOUT ID name
FROM "Stocks/Data"
WHERE (ticker = this.Ticker)

What’s name?
You define the source: FROM "Stocks/Data"
You define one filter: WHERE ticker = this.ticker (attention: this works only if you have only one ticker value per file/note → if not, you need to use the function contains() → if you use a field in frontmatter with [] this automatically create a list, even if only one value > because this you need to use the contains function: something like WHERE contains(ticker, this.ticker))
Now, I ask: what you want to see in the output? The file name? The file link?

TABLE WITHOUT ID file.link as Name
FROM "Stocks/Data"
WHERE contains(ticker, this.ticker)

or, if name is a custom field

TABLE WITHOUT ID name AS Name
FROM "Stocks/Data"
WHERE contains(ticker, this.ticker)

About dvjs, I only know that this doesn’t exists (you need to use dv.current()) and contains also doesn’t exists (I think you need to use .includes())

Hi thanks for your reply.
What’s name ?
=> it’s in the YAML of each file. e.g. name: [“name of the company name”]

You define one filter: WHERE ticker = this.ticker (attention: this works only if you have only one ticker value per file/note → if not, you need to use the function
=> Yes correct, I don’t want to use Contain as it would bring many files, I just want the 1 file where ticker = “BMO.TO” for example.

Now, I ask: what you want to see in the output? The file name? The file link?
=> Yes, the file link and the YAML field “name” as per above.

So…

  1. If only one value in ticker:
  • if in yaml frontmatter you CAN´T use ["value"], just ticker: "BMO.TO" (attention to the ", not “)
  • in an inline field you CAN´T use either ["value"], just ticker:: BMO.TO or ticker:: "BMO.TO"
  1. the query
TABLE name
FROM "Stocks/Data"
WHERE ticker = this.ticker

(Sometimes it’s difficult to give direct answers without all the needed information. For example, a bad syntax in fields can destroy any query attempt.)

1 Like

@mnvwvnm this was very helpful. This was the solution:

  • if in yaml frontmatter you CAN´T use ["value"], just ticker: "BMO.TO" (attention to the ", not “)

I was using ticker : [“BMO”] in the frontmatter.

Thank you.

In yaml if you add []you’re saying “this is a list/array”, even if only one value inside. In that case you need to use contains().
For comparations as single values you need to remove them.

Great, now I know! appreciated.

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