Basic use of inline variables in a simple dataview

It would be so helpful to me if I could figure it out. I’ve searched the forums, searched the dataview vault and guessed a lot. How do I make this work?

UPDATE: In my example, ‘created’ is a value in the frontmatter storing file creation time. I do not use file.ctime because that value is not static.

<-BEGIN NOTE->

date_value:: 2024-06-01

TABLE created
WHERE created > date_value
LIMIT 10

<-END NOTE->

you probably want file.ctime > this.date_value

https://blacksmithgu.github.io/obsidian-dataview/annotation/metadata-pages/

1 Like

Or perhaps something along these lines?

==<-BEGIN NOTE->==  
date_value:: 2024-06-01

Looking for files that have a `date_value` key–value pair where the `value` is greater than the `value` given in this file’s `date_value`:

## 1. query files with a `date_value` greater than this file’s `date_value`

```dataview
TABLE date_value
WHERE date_value
AND date_value > this.date_value
SORT date_value ASC
LIMIT 10
```

## 2. query files with a `date_value` greater than or equal to this file’s `date_value`

```dataview
TABLE date_value
WHERE date_value
AND date_value >= this.date_value
SORT date_value ASC, file.name ASC
LIMIT 10
```

## 3. query files with a `date_value` less than this file’s `date_value`

```dataview
TABLE date_value
WHERE date_value
AND date_value < this.date_value
SORT date_value ASC
LIMIT 10
```

==<-END NOTE->==

‘created’ is actually in the frontmatter and is the file creation time. I don’t use file.ctime because it is easily reset during certain file operations. file.frontmatter.created (auto created with Linter plugin) never changes.

Thanks for the replies!

According to the responses, I think something else is going on. I must be using inline variables incorrectly because I can get all these examples working without the variable, but not with.

For example, this works fine for me:

LIST
FROM #g/active
LIMIT 5

But this doesn’t work:

QUERY_LIMIT:: 5

(Also tried: QUERY_LIMIT:: `= number(5)`)

LIST
FROM #g/active
LIMIT QUERY_LIMIT

It fails with error: Dataview: Failed to execute 'limit' statement: limit should be a number, but got 'null' (null)

Something like this?

==<-BEGIN NOTE->==   
created:: 2024-06-01T17:18    
date_value:: 2024-06-01T17:18

## 0. LIST of #g/active

```dataview
LIST
FROM #g/active
LIMIT 10
```

## 1. `created` value is greater than this file’s `date_value`

```dataview
TABLE created
FROM #g/active
WHERE created
AND created > this.date_value
SORT created ASC
LIMIT 10
```

## 2. `created` value is greater than or equal to this file’s `date_value`

```dataview
TABLE created
FROM #g/active
WHERE created
AND created >= this.date_value
SORT created ASC
LIMIT 10
```

## 3. `created` value is less than this file’s `date_value`

```dataview
TABLE created
FROM #g/active
WHERE created
AND created < this.date_value
SORT created ASC
LIMIT 10
```

==<-END NOTE->==

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