Hi guys, I’m using Dataview to categorize my journaling notes by week, month, year, etc. I have weekly notes that I want to round up in Dataview with the field month. The weekly note template that I use autofills the month for me (thanks to Templater) with the following line of code: <% tp.date.now("YYYY-MM") %>
The problem is that Dataview is not picking up the correct months at all. When I use the following code to pull up what Dataview is reading in the month field:
LIST
WHERE month
FLATTEN month
GROUP BY month
It only sees:
2021-00-01
2022-00-01
<% tp.date.now(“YYYY-MM”) %>
I am expecting Dataview to return keys like 2022-07, I find it very odd that Dataview is picking up a month value of basically zero.
Things I have tried
In the weekly journaling notes, I’ve tried surrounding the month key in quotations and brackets. I’ve double-checked that there is exactly one space separating the colon (from the field name) and the key itself.
1.To debug: month step by step 2.To fix the bug: use dateformat to convert month(Type: date) to string
Code DQL10_debug_TABLE_month_of_estheon
Summary
title: DQL10_debug_TABLE_month_of_estheon =>1.To debug: `month` step by step 2.To fix the bug: use `dateformat` to convert `month`(Type: date) to string
collapse: close
icon:
color:
```dataview
TABLE WITHOUT ID
file.link AS "File",
cash AS "Cash",
month AS "S1_Month",
typeof(month) AS "S2_T_Month",
F_year_month AS "S3_year_month",
F_year_month2 AS "S4_year_month2"
FROM "100_Project/02_dataview/Q96_month/Q96_test_data"
WHERE month
FLATTEN dateformat(month, "yyyy-MM") AS F_year_month
FLATTEN dateformat(file.day, "yyyy-MM") AS F_year_month2
SORT file.name ASC
```
1.To sum up cash 2.WHERE month 3.groupBy GF_year_month
Code DQL20_TABLE_FLATTEN_groupBy
Summary
title: DQL20_TABLE_FLATTEN_groupBy =>1.To sum up cash 2.WHERE month 3.groupBy GF_year_month
collapse: close
icon:
color:
```dataview
TABLE WITHOUT ID
rows.file.link AS "File",
rows.cash AS "Cash",
sum(rows.cash) AS "sum_cash",
GF_year_month AS "year_month"
FROM "100_Project/02_dataview/Q96_month/Q96_test_data"
WHERE month
FLATTEN dateformat(file.day, "yyyy-MM") AS F_year_month
GROUP BY F_year_month AS GF_year_month
SORT GF_year_month ASC
```
Thank you for your response! I was able to try your debugging code on my end. Here is how I paraphrased it:
TABLE WITHOUT ID
file.link AS "File",
month AS "S1_Month",
typeof(month) AS "S2_T_Month",
F_year_month AS "S3_year_month",
F_year_month2 AS "S4_year_month2"
WHERE month
FLATTEN dateformat(month, "yyyy-MM") AS F_year_month
FLATTEN dateformat(file.day, "yyyy-MM")
AS F_year_month2 SORT file.name ASC
Unfortunately, I didn’t get quite the same result as you. Specifically, the dateformat(file.day, "yyyy-MM") returned null output. Do you know what might be going on? I’m using Dataview 0.5.41 and Obsidian 0.15.8.
Actually, I have a different, more specific concern than trying to replicate your results now.
I have this code that selects weekly journaling notes for the month of July 2022:
TABLE
WHERE dateformat(month, "yyyy-MM") = "2022-07"
My new problem is that this code will not select weekly journaling notes that have two values for the month key.
For example, I wrote [2022-07, 2022-08] for the value of the month key in the weekly note for Week 32 since it straddles across two months. The code above does not include this weekly note. (Furthermore, when I surround 2022-07 in brackets in weekly notes that are only part of July 2022, this Dataview code doesn’t select it. So I think Dataview is viewing it as an array that dateformat cannot handle.) What code would also select the note for such note?
The following DQL must contain the typeof function for you in order to gain a deeper understanding of the function.
1.How to distinguish lists from the other data types?
2.How to filter by a list and compare by string?
3.How to filter by a list and compare by date?
typeOf : released at 2022-07-08 from Dataview_v0.5.30
v0.5.30 Added the typeof(any) function in Dataview, which obtains the type of any value for comparison
title: DQL10_distinguish_lists_from_the_other_data_types => 1.Use `typeof` to distinguish lists from the other data types 2.The following DQL must contain the `typeof` function for you in order to gain a deeper understanding of the function.
collapse: close
icon:
color:
```dataview
TABLE WITHOUT ID
file.link AS "File",
dateformat(month, "yyyy-MM") AS "month",
typeof(month) AS "T_month"
FROM "100_Project/02_dataview/Q96_month/20220802_month_02/Q96_test_data_02"
WHERE month
```
title: DQL20_deal_with_lists_only_and_compare_by_string => 1.Use `typeof` to filter by lists 2.Compare by string 3.The following DQL must contain the `typeof` function for you in order to gain a deeper understanding of the function.
collapse: close
icon:
color:
```dataview
TABLE WITHOUT ID
file.link AS "File",
dateformat(month, "yyyy-MM") AS "month"
FROM "100_Project/02_dataview/Q96_month/20220802_month_02/Q96_test_data_02"
WHERE month
WHERE typeof(month) = "array"
WHERE contains(dateformat(month, "yyyy-MM"), "2012-03")
WHERE contains(dateformat(month, "yyyy-MM"), "2012-04")
```
title: DQL30_deal_with_lists_only_and_compare_by_date => 1.Use `typeof` to filter by lists 2.Compare by date 3.The following DQL must contain the `typeof` function for you in order to gain a deeper understanding of the function.
collapse: close
icon:
color:
```dataview
TABLE WITHOUT ID
file.link AS "File",
dateformat(month, "yyyy-MM") AS "month"
FROM "100_Project/02_dataview/Q96_month/20220802_month_02/Q96_test_data_02"
WHERE month
WHERE typeof(month) = "array"
WHERE contains(month, date("2012-03"))
WHERE contains(month, date("2012-04"))
```
Excellent investigating here! Just to add on to what @justdoitcc has written, if you are trying to find something in a list, equality does not work, since the list does not equal one element of that list! Instead contains(list, element) will test whether list contains element. Since your output is strings, and strings are lists of characters internally, contains(dateformat(month...), "2022-07") should work regardless of whether month is a list! If month is not a list, well, “2022-07” does contain “2022-07”!