Using DATAVIEW in one file only

What I’m trying to do

I’m a psychologist, I used to do therapy notes at notion, using one file for each session, but I think it would be better to use only one file to record all notes. When I need to find some info, it’s hard to search the notes opening file per file. But I don’t want to lose the organization multiple files brings.

Searching for solutions I encountered the DATAVIEW plugin and I almost got what I wanted.

I want to have these metadata at each session:

# Session 2

Session:: Session 2
Date:: 06/16/2024
Payment:: 06/09/2024

# Session 1

Session:: Session 1
Date:: 06/09/2024
Payment:: 06/09/2024

Then I want to have a table that look like this:

Session Date Payment
Session 1 06/09/2024 06/09/2024
Session 2 06/16/2024 06/09/2024

Things I have tried

I have tried using FLATTEN and GROUP BY.

TABLE WITHOUT ID Session, Date, Payment
FROM "Notes"
FLATTEN Session AS S
FLATTEN Date AS D

This multiples the records. If I have 20 sessions, I end up with a 400-line or more table

TABLE WITHOUT ID groupSession, Date, Payment
FROM "Notes"
FLATTEN Session AS FSession
FLATTEN Date AS FDate
GROUP BY FSession AS groupSession

This almost get me what I want, but then I loose the other rows


So, is there a way for doing it? Maybe getting the headers instead of the data?

Hi,

Someone had the same problem over there:

You really need to read it the guy who solved it really knows how to use Dataview

summary:
You need first to apply a heading to each session in your note and each metadata of each “session” must be an item of a list below the heading.

then you need to refer to the position of the element of the list for dataview to find it.

I adapted it for you and it worked:

TABLE without ID 

rows.L.Session[0] as Session, 
rows.L.Date[1] as Date, 
rows.L.Payment[2] as Payment

FROM #test

WHERE file.lists

FLATTEN file.lists AS L

WHERE contains(meta(L.section).subpath, "Session")

GROUP BY file.name + meta(L.section).subpath
SORT rows.file.name ASC

PS: you need to keep your metadata in the same order for it to work

Heading

  • session::
  • date::
  • payment

Much depends on how the notes are structured. One note per person?

A simple Dataview query can collate data from multiple files. For example, querying individual files in a folder called “Notes”:

```dataview
TABLE 
Session, Date, Payment, Amount
FROM "Notes"
WHERE file != this.file
SORT file.name ASC
```

Hmm, this almost works. If I use file.lists, then I can’t use use lists anywhere else below the heading, right?

This is what I got, and it seems like these blank lines were the ones where I’ve used lists to type other stuff.

Each person would have one folder, inside that folder I’d have:

Session notes (which is the ones I want to put in the dataview)
Dataview (where I can rapidly verify which sessions were paid or not and when it happened, and maybe some “title” for each session)
Case Conceptualization (where I’d put important information)
Treatment Planning (what I’m planning for this person)

I fixed the blank lines adding:

WHERE contains(meta(L.section).subpath, "Sessão ")

since each heading would be titled like that

now I just need help sorting

you can sorte by date:

SORT rows.L.Date[1] DESC (or ASC)

It didn’t work… I use the date-format dd/mm/aaaa, but it seems like it didn’t recognize it.

Here’s how it sorted:

I tried with dd-mm-aaaa too, with same results

That’s not a date as far as Dataview is concerned, just a string of numbers:

https://blacksmithgu.github.io/obsidian-dataview/annotation/types-of-metadata/#date

Think you can convert it from a string to a date. Or use a date in the recognized format in your value-key pairs.

You’re touching on various subjects when asking this request, but here is an example note with a working query:


## Session 2

 - (Session:: Session 2) [date:: 06/09/2024] [payment:: 06/09/2024]

- (Session:: Session 2b)  
  [date:: 06/16/2024]  
  [payment:: ]

## Session 1

- (Session:: Session 1) [date:: 06/01/2024] [payment:: 06/10/2024]

Introductory stuff...


## Query

```dataview
TABLE WITHOUT ID item.Session as Session, Date, Payment
WHERE file = this.file
FLATTEN file.lists as item
WHERE item.Session
FLATTEN date(item.date, "MM/dd/yyyy") as Date
FLATTEN date(item.payment, "MM/dd/yyyy") as Payment
SORT Date desc
```

First of all I’m using WHERE file = this.file to limit the query to only this one file. You could use notation like already suggested, but there are some caveats with your original and that suggested notation:

  • With your original notation all the fields are gathered up into unconnected lists, as showcased in the linked post. This is because all fields have been declared at the page level (as opposed to in a list or task context)
  • With the suggested usage of lists, you can get it to work, but you need to keep the order of list items in that exact order related to your headings, and you can’t have multiple sessions under the same heading. However, since the fields now are within lists, it can be referenced through the index notation
  • With my suggested notation, a given session is contained within one list item, which makes referencing it a lot easier.

Thirdly, you’re not using a date format which Dataview understands as a date directly, so you’ll need to use date(text, format) to transform it back from a text into a date before you can use like an ordinary date.

So after using FLATTEN date(...) as variable where we store the result of that date transformation, we can present the result you wanted, and you can view the summary of the sessions with payment information.

Also notice how you can vary between ( ... ) and [ ... ] depending on whether you want the key name to be hidden or not.

1 Like

so nice!

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